Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Problem of GetAllIncluding #4357


User avatar
0
itzoar2 created

I find that the GetAllIncluding is not stable

The below is the code that i link all related object out

but from my screenshot, you can see sometimes it can map to the object ProductApproval.Approver1 and sometimes i can't.

Is it because my apsnetboilerplate framework is on version 2.0.2?

should i update to the latest aspnetboilerplate framework?

private IEnumerable<Product> GetProduct(FilterInput input)
        {
            var output = from p in
                     (_productRepo.GetAllIncluding(
                     p => p.Colour,
                     p => p.Unit,
                     p => p.Serie,
                     p => p.Brand,
                     p => p.Supplier,
                     p => p.ProductCategory1,
                     p => p.ProductCategory2,
                     p => p.ProductCategory3,
                     p => p.ProductCategory4,
                     p => p.MinQuantities,
                     p => p.ProductApprovals,
                     p => p.CreatorUser,
                     p => p.CreatorUser.Company
                    ).ToList())
                         where Filter.FilterUtil.FilterForGetProduct(p, input)
                         select p;

            return output;
        }


5 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    GetAllIncluding is single-level. To include nested relationships, add using Microsoft.EntityFrameworkCore; and do:

    var output = from p in
        (_productRepo.GetAllIncluding(
            // ...
            // p => p.ProductApprovals // Comment out this line
            // ...
        ).Include(p => p.ProductApprovals) // Include relationship
            .ThenInclude(pa => pa.Approver1) // ThenInclude nested relationship
        .ToList())
        where Filter.FilterUtil.FilterForGetProduct(p, input)
        select p;
    
  • User Avatar
    0
    alper created
    Support Team

    Hi,

    It's stable and never seen such a doubt. I guess you compare different records. see my screenshot. The both records refer to different entities.

  • User Avatar
    0
    itzoar2 created

    Hi Aaron

    I have changed the the below LINQ

    but it seems the output still cannot get the ProductApprovals object

    I have attached the Domain Entity for your reference too. please advise. Thanks a lot

            var output = from p in
                (_productRepo.GetAllIncluding(
                         p => p.Colour,
                         p => p.Unit,
                         p => p.Serie,
                         p => p.Brand,
                         p => p.Supplier,
                         p => p.ProductCategory1,
                         p => p.ProductCategory2,
                         p => p.ProductCategory3,
                         p => p.ProductCategory4,
                         p => p.MinQuantities,
                         p => p.CreatorUser,
                         p => p.CreatorUser.Company
                ).Include(p => p.ProductApprovals) // Include relationship
                    .ThenInclude(pa => pa.Approver1) // ThenInclude nested relationship
                .ToList())
                         where Filter.FilterUtil.FilterForGetProduct(p, input)
                         select p;
    

  • User Avatar
    0
    alper created
    Support Team

    Nested include <a class="postlink" href="https://stackoverflow.com/questions/15764572/ef-linq-include-multiple-and-nested-entities">https://stackoverflow.com/questions/157 ... d-entities</a>

  • User Avatar
    0
    aaron created
    Support Team

    Remove .First() — you may get an "error" from Intellisense, but it should still compile. See discussion (aspnet/EntityFrameworkCore#6560) and cause (dotnet/roslyn#8237).