简体   繁体   中英

Update on Parent Table with ado.net entity framework with domain services

When I update a Employee I get an exception

"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."

My code receives an Employee , attaches to the context and save changes.

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

The exception happens when a Foreign Key is changed on this object.

How can I attach the object changing this Foreign Key?

您可以查找Key实体并将Employee添加到Key.Employee并保存更改,而不仅仅是附加和保存。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM