gpt4 book ai didi

c# - 使用带有域服务的 ado.net Entity Framework 更新父表

转载 作者:太空狗 更新时间:2023-10-29 23:53:04 24 4
gpt4 key购买 nike

当我更新一个 Employee 时我得到一个异常

"A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship."

我的代码收到一个 Employee,附加到上下文并保存更改。

public void UpdateRAD_Tbl_OrderPatient(Employee emp)
{
try
{
this.ObjectContext.RAD_Tbl_OrderPatient.AttachAsModified(emp);
this.ObjectContext.SaveChanges();
this.ObjectContext.AcceptAllChanges();
}
catch(Exception ex)
{
}
}

fk

异常发生在这个对象的外键改变时。

如何附加更改此外键的对象?

最佳答案

除了附加和保存之外,您还可以查找 Key 实体并将 Employee 添加到 Key.Employee 并保存更改。

关于c# - 使用带有域服务的 ado.net Entity Framework 更新父表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4694426/

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