Stop propagating deletes
- by Mark
Is it just me or is anyone else finding EF very difficult to use in a real app :(
I'm using it as the data layer and have created custom business objects. I'm having difficulty converting the business objects back to EF objects and updating/adding/deleting from the database. Does anyone know a good, simple example of doing this?
Actually the current problem that's driving me nuts is when I delete something EF tries to delete other related stuff as well. For example, if I delete an invoice it will also delete the associated customer! Seems odd. I can't figure out how to stop it doing this.
// tried:
invoiceEfData.CustomerReference = null;
// also tried
invoiceEfData.Customer = null;
context.DeleteObject(invoiceEfData);
context.SaveChanges();
// at this point I get a database error due to it attempting to delete the customer