R – Fluent NHibernate Inheritance Base Class

fluent-nhibernate

I have a Base Class called User. Teacher and Student derive from User class. There is a table called Users.

Users have some common properties which will be used by Teacher and Student classes. The User class mapping looks something like this:

public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Id(x => x.Id).ColumnName("UserId");
            WithTable("Users");
        }
    }

Now, for some reason when I save the Teacher it says FirstName cannot be null. But I am assigning the FirstName

So, basically the question is how to map the base class to a table whose subclasses are also using the same table.

Best Answer

You can look into using the DiscriminatorSubClassesOnColumn method.

Related Topic