问题描述
说我有2个表:Message和SuperMessage和3个实体:Message(base(not abstract)),Comment(继承自Message)和SuperMessage(inherits从消息)
消息具有不可为空的MessageType字段,用作歧视者。
- MessageType = 1表示它是一条消息
- MessageType = 2表示它是一条评论
- MessageType = 3 AND并加入SuperMessage意味着它是一个SuperMessage
问题是我无法在SuperMessage的映射详细信息部分的MessageType上指定一个条件,因为它不能看到MessageType字段,我不能忽视它。
我如何使这些工作与eachother一起工作?
UPDATE 构建错误:
错误3014:映射片段中的问题:外键外键约束FK_SuperMessage_inherits_Message从表SuperMessage(ID)到表Message(MessageId):'没有在模型中执行。需要创建一个关联或继承关系以执行这个约束。
我转载了这个,并且得到了和你一样的错误。据我所知,似乎将这两种继承类型组合在一个单独的基表中是不可能的。我很想被证明是错的。 ; - )
Say I have 2 tables: Message and SuperMessage
and 3 entities: Message (base (not abstract)), Comment (inherits from Message) and SuperMessage (inherits from Message)
Message has a non-nullable MessageType field which is used as a discriminator.
- MessageType = 1 means it is a Message
- MessageType = 2 means it is a Comment
- MessageType = 3 AND and join to the SuperMessage means it is a SuperMessage
The problem is that I cannot specify a condition on MessageType of the SuperMessage's Mapping details section because it cannot see the MessageType field and I cannot ignore it.
How can I make these work alongside eachother?
UPDATE Build Error:
Error 3014: Problem in mapping fragments:The foreign key 'Foreign key constraint 'FK_SuperMessage_inherits_Message' from table SuperMessage (ID) to table Message (MessageId):' is not being enforced in the model. An Association or inheritance relationship needs to be created to enforce this constraint.
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. ;-)
这篇关于我可以在实体框架中混合每个层次表和每个类型的表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!