"X"表示"Y"上的属性无法设置为"null"值.您必须将此属性设置为'Int32'类型的非空值 [英] The "X" property on "Y" could not be set to a 'null' value. You must set this property to a non-null value of type 'Int32'

查看:78
本文介绍了"X"表示"Y"上的属性无法设置为"null"值.您必须将此属性设置为'Int32'类型的非空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的应用程序并单击特定按钮时,出现错误:

When I run my application and I click a specific button I get the error:

"The "X" property on "Y" could not be set to a 'null' value. You must set this property to a non-null value of type 'Int32'."

很酷,所以我转到Entity项目,转到Y表,找到X列,右键单击并转到X的属性,然后将Nullable设置为False.

Cool so I go to my Entity project, go to Y table, find X column, right-click and go to X's properties and find that Nullable is set to False.

我在SQL中验证是否在Y表中将X设置为允许空值.

I verify in SQL that in Y table, X is set to allow nulls, and it is.

然后我回到我的实体项目,将Nullable设置为True,保存并构建,然后我收到:

I then go back to my Entity project, set Nullable to True, save and build and I receive:

Error 3031: Problem in mapping fragments starting at line 4049:Non-nullable column "X" in table "Y" is mapped to a nullable entity property.

我听说从.edmx文件中删除表然后重新添加它是有可能的,但是从未这样做过,并且不了解这样做的含义.

I've heard that deleting the table from the .edmx file and then re-adding it is a possibility but have never done that and don't understand the implications enough to feel comfortable in doing that.

我听说它可能在视图中,也可能在存储过程中……

I've heard that it could be in the view, could be in the stored procedure...

也听说这是一个错误.

有没有人遇到这个问题,找到了全面"修复程序,或者在哪里寻找此错误的某种路线图?

Has anyone come across this and found an "across the board" fix or somewhat of a road map of sorts on where to look for this error?

谢谢!

推荐答案

 "The "X" property on "Y" could not be set to a 'null' value. You must set this property to a non-null value of type 'Int32'."

在EDMX中,如果转到Y表下方,然后单击X列,右键单击,单击属性",向下滚动到 Nullable ,然后从 False 更改到 True .

In your EDMX, if you go under your Y table and click on X column, right-click, click on Properties, scroll down to Nullable and change from False to True.

如果出现映射片段"错误,则必须从EDMX中删除该表并重新添加它,因为在模型浏览器中,它存储了表属性以及刷新该表属性的唯一方法(即知道)是从模型浏览器中的< database>下删除该表.存储,然后使用 Update Database from Database .. 命令检索该表.

If you get a "mapping fragment" error, you'll have to delete the table from the EDMX and re-add it, because in the Model Browser it stores the table properties and the only way to refresh that (that I know of) is to delete the table from the Model Browser under <database>.Store then retrieving it using Update Model from Database.. command.

这篇关于"X"表示"Y"上的属性无法设置为"null"值.您必须将此属性设置为'Int32'类型的非空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆