Skip to content

Instantly share code, notes, and snippets.

@JoshClose
Created November 15, 2011 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshClose/1367399 to your computer and use it in GitHub Desktop.
Save JoshClose/1367399 to your computer and use it in GitHub Desktop.
The New World of NHibernate
// This:
session.CreateCriteria( typeof( MyClass ) ).Add( Expression.Eq( "Name", name ) );
// Becomes this:
session.CreateCriteria( typeof( MyClass ) ).Add<MyClass>( m => m.Name == name ).List();
public class MyClass
{
public virtual int? Id { get; private set; }
public virtual string Name { get; set; }
public virtual MyReference MyReference { get; set; }
public virtual IList<MyReference> MyReferenceCollection { get; private set; }
}
public class MyClassMap : ClassMap<MyClass>
{
public MyClassMap()
{
Id( m => m.Id );
Map( m => m.Name );
References( m => m.MyReference );
HasMany( m => m.MyReferenceCollection );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment