Skip to content

Instantly share code, notes, and snippets.

@GeradeDev
Created August 14, 2019 18:34
Show Gist options
  • Save GeradeDev/596be615b7f7fd00fb2077b0c2df829d to your computer and use it in GitHub Desktop.
Save GeradeDev/596be615b7f7fd00fb2077b0c2df829d to your computer and use it in GitHub Desktop.
using (var context = new OrderingDbContext())
{
// Load all Orders and related Line Items
var orders = context.Order
.Include(b => b.LineItem)
.ToList();
// Load an Order and it's related Line Items
var orders = context.Order
.Where(x => x.OrderId == orderId)
.Include(b => b.LineItem)
.ToList();
// Multiple levels deep
// Load all order, all related line items, and all related reviews for that line item (product)
var orders1 = context.Order
.Include(b => b.LineItem.Select(p => p.Review))
.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment