Referential Integrity Constraint violation when attempting to set a FK to null

c# entity-framework referential-integrity

Question

In EF6, I'm attempting to update an entity. According to what I've read, if I want to update a ForeignKey property, I must first check that the Navigation Property is the right one, else, I must set it to null.

Despite using the set to null method, the Referential Integrity Constraint Exception persists.

A referential integrity constraint violation occurred: The property value(s) of 'Contact.idContact' on one end of a relationship do not match the property value(s) of 'Entity.id_EntityContactInfo' on the other end.

However, that Entity may be seen in the debugger. I don't think this should be throwing because there was no contact.

enter image description here

Any suggestions?

EDIT

The entity is updated as follows:

public T CommitUpdate<T>(T obj) where T : class
    {
        _DbContext.Set<T>().Attach(obj);
        _DbContext.Entry(obj).State = EntityState.Modified;
        _DbContext.Commit();
        return obj;
    }
1
9
8/15/2014 2:45:22 AM

Popular Answer

ZZZ_tmp
9
8/15/2014 9:40:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow