views:

33

answers:

1

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
A: 

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>
Joel Martinez
Thanks for the quick reply Joel. Sorry to say that I was completely confused. I fired up SQL Profiler and it turns out the problem was something else entirely. I'll have to try a bit harder next time before turning to Stackoverflow. - cheers Mark.
Mark Evans
Just out of curiosity, what was the problem? (for the benefit of future people arriving via bing/google (bingle?)
Joel Martinez
Can I delete the whole thing? It was really a waste of time. It wasn't trying to delete a customer at all. I just assumed this from the error message. When I ran a database trace it was deleting something else (that I asked it to delete) and this was causing the error message :(
Mark Evans