Stop propagating deletes

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

Answers


Are you sure your database is not set up to try to do cascading deletes?

One other thing to check, crack open the .edmx file in the xml editor and see if you have a line like this that relates to the entity in question:

<OnDelete Action="Cascade"></OnDelete>

Need Your Help

Assembly analyzing system() function called in C

c assembly intel

So I made a very simple C program to study how C works on the inside. It has just 1 line in the main() excluding return 0: