实体框架Windows Froms Visual Studio 2010 Beta 2 ERROR在转出DataGridView New Row后调用Context.SaveChanges()时出现错误 [英] Entity Framework Windows Froms Visual Studio 2010 Beta 2 ERROR when calling Context.SaveChanges() after escaping out of DataGridView New Row

查看:60
本文介绍了实体框架Windows Froms Visual Studio 2010 Beta 2 ERROR在转出DataGridView New Row后调用Context.SaveChanges()时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的人力资源应用程序,使用ado.net实体,用户选择一个人,在DataGridView中加载所选的员工联系信息。

但是,假设我添加一个新的电话号码然后意识到我犯了一个错误并从数据网格视图的新行中击出Escape(esc)
在击中Escape两次后,新行就像它应该的那样消失。

我检查了ContactInfo DataObject,添加(并转出)的新行不存在......这是正确的。

调用context.saveChanges()时出现以下错误无论我是否做出其他改变。 Context是我的EntityFramework Ba​​se实例的原因

操作失败:由于一个或多个外键属性不可为空,因此无法更改关系。当对关系进行更改时,相关的外键属性将设置为空值。如果外键不支持空值,则必须定义新关系,必须为外键属性分配另一个非空值,或者必须删除不相关的对象。

任何想法?

I have a basic HR application, using ado.net entities, the user picks a person, in a DataGridView the selected Employees Contact Information is loaded.

However, Say I add a new Phone number, then realize i made a mistake and hit Escape (esc) out of the new row of the datagridview

After hitting Escape twice the new row goes away like it should.

I've checked the ContactInfo DataObject and the new row that was added (and escaped out of) does not exist ... which is correct.

I get the following error when calling context.saveChanges() weither or not i make other changes. Where Context is My EntityFramework Base Instance


The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.

Any Ideas?

推荐答案

您是否检查了上下文的ObjectStateManager以确保没有新的ContactInfo对象实例?
Have you checked the context's ObjectStateManager to make sure that there really is no new instance of a ContactInfo object?

这篇关于实体框架Windows Froms Visual Studio 2010 Beta 2 ERROR在转出DataGridView New Row后调用Context.SaveChanges()时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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