When working with one-to-many relationships, i get the following error at the mybase.savechanges():

An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types.

The innerexeption is this:{"A relationship from the 'DepartementCustomer' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Customer' must also in the 'Deleted' state."}

Replies To: Soft delete with entity framework 4.1

Re: Soft delete with entity framework 4.1

Posted 04 September 2012 - 10:56 AM

Pretty sure you have to grab the customer (as indicated by the message) and remove that instance of the customer as well. You are basically deleting one column from a junction table but not the subsequent column...so if you're junction table is:

Department/Customer...you are removing the department and leaving the customer...but the customer has to have a department and thus, this save errors out. That instance needs both key values else both key values need to be handled....

So....You have to get the entity dept and entity customer that you need for this delete and remove the relationship from both sides...not just one.