gpt4 book ai didi

c# - 使列不可为空,EF 外键错误

转载 作者:行者123 更新时间:2023-11-30 20:45:35 25 4
gpt4 key购买 nike

我将表中的列从 NULL 更改为 NOT NULL,从数据库更新模型,现在出现以下错误:

Error 3 Running transformation: Multiplicity conflicts with the referential constraint in Role 'registration' in relationship 'fk_cost_centre_registration'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.

我不确定如何解决这个问题。我做错了什么?

我修改过的其中一个表上的很多导航属性都做了很多修改,不能删掉再重新添加,要不然我需要重命名所有的导航属性并去掉很多我不需要,可能会出现回归问题。这是我在使用 EF 时面临的另一个问题——因为我更改了一些导航属性,删除和读取表格是一个大问题。是的,我可以记录我需要的属性,但是 - 也许我做错了什么?

最佳答案

只需通过属性选项卡更改多重性。如果 Dependent Role 可以为 null,则其多重性将为 0..1(零或其中之一 ...)。如果它不可为空,则它应该是 1(...之一)。所以打开你的模型,找到你的外键并改变适当的多重性,如图所示

enter image description here

enter image description here

关于c# - 使列不可为空,EF 外键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27993093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com