MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 175 forks source link

Select in linq-supported-include is not imported by IncludeEFU #67

Open maleet opened 8 years ago

maleet commented 8 years ago

This kind of linq-supported-include is not imported by IncludeEFU.

Plain LinqToEntity: var firstOrDefault = db.Comments.Include(x => x.Publication.Comments.Select(comment => comment.Address)).FirstOrDefault();

With IncludeEFU: var firstOrDefault = db.Comments.IncludeEFU(db, x => x.Publication.Comments.Select(comment => comment.Address)).FirstOrDefault();

Can I do Include children of children?

maleet commented 8 years ago

Not the best example from me as something similar is explained here: https://github.com/MikaelEliasson/EntityFramework.Utilities/issues/14

My query is following:

var purchaseOrderHeader = Entities.PurchaseOrderHeaderDetails
    .Include(x => x.PurchaseOrderType)
    .IncludeEFU(Entities, x => x.PurchaseOrderLines
        .Select(line => line.PurchaseOrderProcedureActivities))
    .IncludeEFU(Entities, x => x.PurchaseOrderLines
        .Select(l => l.ItemDetailHeaders
            .Select(pdh => pdh.ItemDetailLines)))
    .IncludeEFU(Entities, x => x.PurchaseOrderLines
        .Select(l => l.PurchaseOrderLineAllocations
            .Select(pola => pola.ItemDetailHeaders
                .Select(header => header.ItemDetailLines))))
    .FirstOrDefault(x => x.Id == id);

Here PurchaseOrderHeaderDetails have list of PurchaseOrderLines and PurchaseOrderLine have list of PurchaseOrderProcedureActivities