Stop propagating deletes

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-03-25T01:34:46Z Indexed on 2010/03/25 1:43 UTC
Read the original article Hit count: 361

Filed under:

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

© Stack Overflow or respective owner

Related posts about entity-framework