Can I mix Table per Hierarchy and Table per Type in Entity Framework?

后端 未结 2 850
梦毁少年i
梦毁少年i 2020-12-07 01:46

Say I have 2 tables: Message and SuperMessage

and 3 entities: Message (base (not abstract)), Comment (inherits from Message) and SuperMessage (inherits from Message)

相关标签:
2条回答
  • 2020-12-07 02:14

    I reproduced this and got the same error as you. As far as I can tell, it appears that combining these two types of inheritance for a single base table is just not possible. I'd love to be proved wrong though. ;-)

    0 讨论(0)
  • 2020-12-07 02:23

    Have you tried adding an intermediate abstract entity type, i.e.:

    abstract     MessageBase      --> Message table
    non-abstract Message          --> Message table when MessageType == 1
    non-abstract Comment          --> Message table when MessageType == 2
    abstract     SuperMessageBase --> Message table when MessageType == 3
    non-abstract SuperMessage     --> SuperMessage table
    

    Also check out a similar scenario I solved: EF: Can I mix TPH and TPT when abstract base and a few concrete types are in TPH-table and other types have their own table?

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