Entity Framework persistence optimization

When dealing with DML statements, EF shows some limitations due to its object orientation. An example on all comes with a DELETE statement made in EF. This example shows how to make a master-detail delete operation:

int InvoiceID = 11; using (var db = new InvoicingDBContainer()) { //materialize an invoice //this will produce a SELECT statement var invoice = db.Invoice .Include("InvoiceElement") //eager-load elements for deletion .FirstOrDefault(x => x.InvoiceID == InvoiceID); //manually load elements for deletion //no lazy-load works for cascade delete objects //db.Entry(invoice).Collection("InvoiceElement").Load(); //informs EF context to remove invoice from database db.Invoice.Remove(invoice); //asks ...

Get Learning .NET High-performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.