Fluent NHibernate entity HasMany collections of different subclass types

后端 未结 1 769
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 23:17

So everything is working well with the basic discriminator mapping. I can interact directly with entities A and B without any problems.

public class BaseType {}
         


        
1条回答
  •  渐次进展
    2021-02-03 23:41

    You mapping looks odd, in particular I think it should look more like this

    DiscriminateSubClassesOnColumn("Type")
                   .SubClass("A", m => { })
                   .SubClass("B", m => { });
    

    Having said that it seems that method is depreciated and you should instead define the following (taken from Automapping Subclasses:

    public class ParentMap : ClassMap
    {
      public ParentMap()
      {
        Id(x => x.Id);
        Map(x => x.Name);
    
        DiscriminateSubClassesOnColumn("type");
      }
    }
    
    public class ChildMap : SubclassMap
    {
      public ChildMap()
      {
        Map(x => x.AnotherProperty);
      }
    } 
    

    Not sure this will fix it though, I am yet to encounter your scenario.

    Edit: The issue is also raised here, sounding more like a bug to me

    0 讨论(0)
提交回复
热议问题