I am coming from the Entity Framework in NHibernate. When I look at how to create domain objects, I noticed that in some examples they do not include a foreign key relationship column. Since the class Sessioncontains a method Load(), you can simply use objects without going to the database instead of primary keys. Is this common practice when creating entity models in NHibernate.
Object Example
public class BlogPost : Entity
{
public virtual string Name { get; set; }
public virtual int AuthorID { get; set; }
public virtual Author Author { get; set; }
}
Object Creation
BlogPost post = new BlogPost
{
Name = "My first post",
Author = session.Load<Author>(1)
};
session.Save(post);
- OR ---
BlogPost post = new BlogPost
{
Name = "My first post",
AuthorID = 1
};
session.Save(post);
source
share