NHibernate mapping for subclasses and joined-subclasses

Posted by Husain on Stack Overflow See other posts from Stack Overflow or by Husain
Published on 2010-04-19T12:44:47Z Indexed on 2010/04/19 13:23 UTC
Read the original article Hit count: 292

In a project that I am working on, I have the following entities: Analyst, Client and Contractor. Each inherit from a base class User.

public abstract class User {
    public virtual int Id { get; set; }
    public virtual string Username { get; set; }
    public virtual string FullName { get; set; }
}

I then have the other classes inheriting from the base class as:

public class Analyst : User {
    // Empty class. There are no additional properties for an analyst.
}

public class Client : User {
    // Empty class. There are no additional properties for a client.
}

public class Contractor : User {
    public int TotalJobs { get; set; }
    public int JobsInProgress { get; set; }
}

For the above classes, I have the following table structure:

USER
----
UserId
Username
FullName
UserType (1 = Analyst, 2 = Client, 3 = Contractor)


CONTRACTOR
----------
UserId
TotalJobs
JobsInProgress

There are no tables for Analyst and Client classes.

I would like to know how I can write the NHibernate mapping file for the Contractor class. For the other classes, I have created a User mapping file and added Client and Analyst as sub-classes. How can I map the Contractor class?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about nhibernate-mapping