Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbSet.Include operator for ef7 accepting string path

EF6 has an overload of DbSet.Include which accepts a string parameter representing a dot-separated list of related objects to return in the query results. It is useful for eager-loading entities in a multi-level object graph. For example:

var order = await _dbContext.Orders
    .Include(o => o.Customer)
    .Include("OrderDetails.Product") // dot-delimited path
    .SingleOrDefaultAsync(o => o.OrderId == id);

This will return both related order details and populate the Product property of each detail by generating a SQL statement that joins OrderDetail and Product tables.

I am looking a way to do this with EF7, but I don't see an overload of DbSet.Include which accepts a string path parameter. Does EF7 provide a way to achieve the same result as the EF6 API?

PS. I just noticed issue #1151 is open, and it looks like it may address my question.

like image 206
Anthony Sneed Avatar asked Dec 24 '14 09:12

Anthony Sneed


1 Answers

You are correct that #1151 is tracking this scenario. There are also some design meeting notes that summarize the API that will be available in EF7 - https://github.com/aspnet/EntityFramework/wiki/Design-Meeting-Notes:-January-8,-2015.

like image 192
Rowan Miller Avatar answered Nov 18 '22 06:11

Rowan Miller