Fluent Nhibernate How to specify Id () in SubclassMap

I'm in the process of adapting Fluent NHibernate to an existing legacy application and trying to determine how to use ClassMap and SubclassMap for the entity hierarchy shown.

// BaseObject contains database columns common to every table
public class BaseObject
{
    // does NOT contain database id column
    public string CommonDbCol1 { get; set; }
    public string CommonDbCol2 { get; set; }
    // ...
}

public class Entity1 : BaseObject
{
    public int Entity1Id { get; set; }
    // other Entity1 properties
}

public class Entity2 : BaseObject
{
    public int Entity2Id { get; set; }
    // other Entity2 properties
}

The identity columns for Entity1 and Entity2 are uniquely identified for each table. BaseObject contains columns that are common to all of our objects. I do not use AutoMapping, and thought I could use ClassMap in BaseObject and then use SubclassMap for each Entity, like this:

public class Entity1Map : SubclassMap<Entity1>
{
    public Entity1Map()
    {
        Id(x => x.Entity1Id);
        // ...
    }
}

The problem is that Id () is not defined for SubclassMap. So, how can I indicate in each Entity1Map, Entity2Map, ... (we have 100+ entity classes, all inheriting from BaseObject), what is an object identifier?

Thanks in advance for your understanding!

+3
1

Fluent NHibernate, NHibernate. , , , ? , , , ; , ClassMap<T> where T : BaseObject .

- :

public abstract class BaseObjectMap<T> : ClassMap<T> where T : BaseObject
{
  public BaseObjectMap()
  {
    Map(x => x.CommonProperty1);
  }
}
+8

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


All Articles