Fluent NHibernate entity HasMany collections of different subclass types

后端 未结 1 767
被撕碎了的回忆
被撕碎了的回忆 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<string>("Type")
                   .SubClass<EntityA>("A", m => { })
                   .SubClass<EntityB>("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<Parent>
    {
      public ParentMap()
      {
        Id(x => x.Id);
        Map(x => x.Name);
    
        DiscriminateSubClassesOnColumn("type");
      }
    }
    
    public class ChildMap : SubclassMap<Child>
    {
      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)
提交回复
热议问题