The Entities folder contains the entities of the system that the system models. The example code contains the definition of three entities: Category, Expense, and User.

The code for Category is as follows:

    public class Category { 
        public virtual int CategoryId { get; set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
        public virtual IList<Expense> Expenses { get; set; }

You will note that all properties of the entity are decorated with the virtual keyword. This allows Fluent NHibernate to override the properties on the entity and assign values and also to create proxies of the entities to enable lazy loading.

When creating your entities for use with Fluent NHibernate, it might be a good idea to create an abstract base entity class from which all of your entities can inherit. This base class can allow you to define a common Id property and to override the Equals and GetHashCode methods. There are many articles and tutorials discussing this topic. Here are some references to get you started include:

Last edited Aug 21, 2015 at 12:22 AM by TheNephalim, version 3


No comments yet.