NHibernate mapping for subclasses and merged subclasses

In the project I'm working on, I have the following people: analyst, client and contractor. Each inherits 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; }
}

Then I have other classes inheriting from the base class:

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 the Analyst and Client classes.

I would like to know how I can write an NHibernate mapping file for the Contractor class. For other classes, I created a user mapping file and added Client and Analyst as subclasses. How can I match the class of the Contractor?

+3
source share
2 answers

, 8.1.4.

<subclass name="Contractor" discriminator-value=3>
  <join table="CONTRACTOR">
    <key column="UserId"/>
    <property name="TotalJobs"/>
    <property name="JobsInProgress"/>
  </join>
</subclass>
+2

Source: https://habr.com/ru/post/1741769/


All Articles