2

I have a method with an queryable expression. Is it possible to reuse the function in a different function, passing in an queryable?

public static IQueryable<IProduct> Product(IQueryable<IProduct> dbSet)
{
    var result = ProductLite(dbSet)
        .Include(prd => prd.GraphicItems)
            .ThenInclude(itm => itm.Graphic)
                .ThenInclude(gfx => gfx.Items)
        .Include(prd => prd.GraphicItems)
            .ThenInclude(gfx => gfx.Culture)
                .ThenInclude(cult => cult.Items)
        .Include(prd => prd.Feedback)
            .ThenInclude(item => item.Culture)
        .Include(prd => prd.Feedback)
            .ThenInclude(feed => feed.Customer)
                .ThenInclude(cust => cust.Culture)
        .Include(prd => prd.Feedback)
            .ThenInclude(feed => feed.Votes)
                .ThenInclude(vote => vote.Customer)
        .Include(prd => prd.Stock)
        .Include(prd => prd.Campaigns)
            .ThenInclude(camp => camp.Campaign)
        .Include(prd => prd.Campaigns)
            .ThenInclude(camp => camp.Culture)
                .ThenInclude(cult => cult.Items)
                    .ThenInclude(itm => itm.Culture)
        .Include(prd => prd.SubscriptionItems)
            .ThenInclude(sub => sub.Culture)
        .Include(prd => prd.Links)
        .Include(prd => prd.Meta);

    return result;
}

The function where I need to reuse the Product function:

public static IQueryable<IStore> Store(IQueryable<IStore> dbSet)
{
    var result = StoreLite(dbSet)
        .Include(str => str.Categorys)
            .ThenInclude(cat => cat.Products)
}
SteinTheRuler
  • 3,549
  • 4
  • 35
  • 71
  • [I really really really recommend that you don't do this. This is going to be an absolutely horrifically in terms of performance.](https://stackoverflow.com/questions/22161234/optimize-entity-framework-query/22625208#22625208) – Erik Philips Feb 28 '18 at 04:00
  • 1
    how do you recommend to query for the related data? – SteinTheRuler Feb 28 '18 at 05:20
  • Read the link in my comment. – Erik Philips Feb 28 '18 at 05:23
  • thanks, I'll look into changing when it supports ef core – SteinTheRuler Feb 28 '18 at 05:46
  • 1
    @ErikPhilips EF Core processes includes differently (not with single query), so the EF6 link and concerns do not apply here. – Ivan Stoev Feb 28 '18 at 07:22
  • it would be great if its possible to reuse a queryable expression since I need to load products at lest three places, and then not having to duplicate code three places – SteinTheRuler Feb 28 '18 at 10:55
  • 1
    @IvanStoev Granted I have not used EF core yet, but the [documentation clearly states: You can combine all of this to include related data from multiple levels and multiple roots in the same query](https://learn.microsoft.com/en-us/ef/core/querying/related-data), I guess it could be wrong.. it's happened before. – Erik Philips Feb 28 '18 at 20:24
  • yeah I kinda know it's possible, I just can't figure out the syntax to pass in Products from the Include statement – SteinTheRuler Feb 28 '18 at 21:55

0 Answers0