Fluent NHibernate tries to map a subclass of a subclass using a table per subclass

I am creating a heavy inheritance application and have a part where classes A, B and C exist with:

class A

class B: A

class C: B

I implemented subclass matching as a style for each subclass for class B as follows:

class BMap : SubclassMap<B> { public BMap() { Extends<A>(); KeyColumn("ID"); } } 

Which works great. However, when I want to implement C as follows:

 class CMap : SubclassMap<C> { public CMap() { Extends<B>(); KeyColumn("ID"); } } 

This results in an error.

 Duplicate class/entity mapping 

I looked at the Hibernate / NHibernate forum, but could not find an answer to this problem.

+4
source share
1 answer

this works as expected with NH 3.3.1.4000

 public class A { public virtual int Id { get; protected set; } } public class B : A { } public class C : B { } public class AMap : ClassMap<A> { public AMap() { Id(x => x.Id); } } public class BMap : SubclassMap<B> { } public class CMap : SubclassMap<C> { } public static void Main(string[] args) { var config = Fluently.Configure() .Database(SQLiteConfiguration.Standard.InMemory().ShowSql().FormatSql()) .Mappings(m => m.FluentMappings .Add<AMap>() .Add<BMap>() .Add<CMap>() ) .BuildConfiguration(); using (var sf = config.BuildSessionFactory()) using (var session = sf.OpenSession()) { new SchemaExport(config).Execute(true, true, false, session.Connection, null); session.Save(new C()); session.Flush(); } } 
+1
source

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


All Articles