New to the EF, I have an issue.
OK, so, I have an Entity with a related Table (one-to-many relationship). The entity holds a collection of child objects from the related table. I want to remove an object from the related collection but not from the child table.
However, when I call <entity>.myRelatedChildTable.Remove( childEntity )
and then call the _context.SaveChanges( )
, I get an exception about ForeignKey Constraints. Now, if I call the _context.DeleteObject()
and then _context.SaveChanges()
we have no problem. But, now we have no child entity as well--it is deleted from the db.
here is the text of the Exception: 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.
anyone have an idea/suggestion how I can fix this?