Inheritance Mapping with Fluent NHibernate

后端 未结 4 2141
既然无缘
既然无缘 2020-12-04 18:15

Given the following scenario, I want map the type hierarchy to the database schema using Fluent NHibernate.

I am using NHibernate 2.0


Type Hier

4条回答
  •  青春惊慌失措
    2020-12-04 18:53

    This is how I resolved my inheritance problem:

    public static class DataObjectBaseExtension
    {
        public static void DefaultMap(this ClassMap DDL) where T : IUserAuditable 
        {
            DDL.Map(p => p.AddedUser).Column("AddedUser");
            DDL.Map(p => p.UpdatedUser).Column("UpdatedUser");
        }
    }
    

    You can then add this to your superclass map constructor:

    internal class PatientMap : ClassMap
    {
        public PatientMap()
        {
            Id(p => p.GUID).Column("GUID");
            Map(p => p.LocalIdentifier).Not.Nullable();
            Map(p => p.DateOfBirth).Not.Nullable();
            References(p => p.Sex).Column("RVSexGUID");
            References(p => p.Ethnicity).Column("RVEthnicityGUID");
    
            this.DefaultMap();
        }
    
    
    }
    

提交回复
热议问题