ADO.Net EF,映射问题
我有以下实体,我遇到的问题是我有一个继承自 MediaItem 的类型 Game。我已将游戏集合传递给视图,并且希望能够将游戏评级(存储在 LibraryItemRating 内)显示为评级。目前我无法做到这一点,因为当我到达 Game.Libraryitems 时,我有一个集合。
我希望 LibraryItems 与 MediaItem 的关联为 1 -- * 而不是 * -- 1。 唯一合理的引用约束是主体:MediaItem (MediaItemID) 和从属:(MediaItem)。设置后,我只能有 * -- 1 关系,否则我会收到以下两个错误:
角色中的多重性无效 关系中的“LibraryItem” '媒体项目库项目'。因为 依赖角色属性不是 关键属性,上限 从属角色的多重性 必须是*。
和
多重性在角色中无效 关系中的“MediaItem” '媒体项目库项目'。有效值 对于主要角色的多重性 是“0..1”或“1”。
任何帮助将不胜感激!这是一个屏幕截图:
注意:MediaItem(MediaItemID) 映射到 LibraryItem(MediaItem)
I have the following Entities and the issue I am having is that I have a type Game which inherits from MediaItem. I have passed a collection of Game to a view and I want to be able to display the Games Rating (Stored inside LibraryItemRating) as Rating. Currently I cannot do this, as when I get to Game.Libraryitems I have a collection..
I want LibraryItems association with MediaItem to be 1 -- * and not * -- 1.
The only referential constraint which is sensible is Principal: MediaItem (MediaItemID) and Dependent: (MediaItem). When this is set I can only have the * -- 1 relationship, otherwise I get these two errors:
Multiplicity is not valid in Role
'LibraryItem' in relationship
'MediaItemLibraryItem'. Because the
Dependent Role properties are not the
key properties, the upper bound of the
multiplicity of the Dependent Role
must be *.
and
Multiplicity is not valid in role
'MediaItem' in relationship
'MediaItemLibraryItem'. Valid values
for multiplicity for Principal Role
are '0..1' or '1'.
Any help would be appreciated! Here is a screenshot:
Note: MediaItem(MediaItemID) maps to LibraryItem(MediaItem)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前的设置无法实现这种多样性。您当前的设置表示:一个 MediaItem 可以位于多个 LibraryItem 中。 这意味着
MediaItem
是主体,LibraryItem
是依赖的,因此它具有FK 属性MediaItem
。如果您想要反向关系,则含义将是:一个 LibraryItem 可以有多个 MediaItem。 在这种情况下,LibraryItem
将成为主体,MediaItem
将成为依赖,因此您还必须更改您的实体:LibraryItem
和MediaItem
之间的关系。它还应该删除两侧的导航属性。LibraryItem
实体中的MediaItem
属性。LibraryItem
FK 属性添加到MediaItem
实体 在LibraryItem
和MediaItem
之间创建新关联并映射引用约束以满足您的需求。You can't have that multiplicity with your current setup. Your current setup says: One MediaItem can be in multiple LibraryItems. It means that
MediaItem
is principal andLibraryItem
is dependent and because of that it has FK propertyMediaItem
. If you want the reverse relation the meaning will be: One LibraryItem can have multiple MediaItems. In such caseLibraryItem
will become principal andMediaItem
will became dependent and because of that you also must change your entities:LibraryItem
andMediaItem
. It should also remove navigation properties on both sides.MediaItem
property inLibraryItem
entity.LibraryItem
FK property toMediaItem
entityLibraryItem
andMediaItem
and map referential constraints to fulfill your needs.