O'Reilly logo

Learning .NET High-performance Programming by Antonio Esposito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required