2

这是我的表(整个事情的一部分,活动表与其他表还有其他关系):

在此处输入图像描述

在我的 Visual Studio 中添加外键并从数据库中更新我的模型 EDMX 后,出现了以下 2 个错误:

错误2 错误112:引用约束的Dependent Role中所有属性的类型必须与Principal Role中对应的属性类型相同。实体“istellarModel1.singalong”上的属性“ActivityID”类型与引用约束“FK_singalong_activity”中实体“istellarModel1.activity”上的属性“ActivityID”类型不匹配。

错误 1 ​​错误 113:多重性在关系“FK_singalong_activity”中的角色“活动”中无效。因为从属角色中的所有属性都可以为空,所以主体角色的多重性必须为“0..1”。

我在 singalong 中检查了我的 ActivityID 与活动表的 Activity ID 具有相同的类型,但我不明白错误 113 的实际含义,我是数据库新手,起初我有很多没有链接的表,所以我将它们链接起来一段时间后并在视觉工作室(使用实体框架)中更新我的模型(EDMX),它给了我错误。

请问这方面有什么指导吗?

在此处输入图像描述

4

2 回答 2

1

The 113 error sounds like your activity ID in singalong is NULLable.

It's stating that many-to-one is not valid if the dependent role is nullable.

That also seems to suggest the reason for the 112 - it's most likely complaining because it considers NOT NULL part of the type as well, so the two columns are different.

A quick fix may be to ensure that singalong.ActivityID is marked a NOT NULL but this will be problematic if you want singalong records with no corresponding activity.

I know how I'd fix it, at least initially, but it may be frowned upon be more knowledgeable DBAs: I'd simply add a dummy activity (eg, activity id = 0) to use for those cases where you would normally have NULL in the singalong table. I'm not suggesting you do that, but it's a possibility I would examine as a temporary fix, being far more of a pragmatist than dogmatist :-)

于 2013-08-29T03:47:42.237 回答
1

我知道这是一个老问题,但遇到了同样的问题,这里是修复。

如果您打开 .edmx 文件(使用实体框架),您将看到不同的表。如果单击链接表格的行:

表

它将显示属性。选择 Multiplicity 并设置为 0..1 您的外键需要设置为可为空。

在此处输入图像描述

于 2021-02-10T19:20:22.157 回答