How do you avoid the EF Core 3.0 “Restricted client evaluation” error when trying to order data from a one-to-many join?

前端 未结 2 795
轮回少年
轮回少年 2021-01-26 10:49

I have a table I\'m displaying in a site which is pulling data from a few different SQL tables. For reference, I\'m following this guide to set up a sortable table. Simplify the

2条回答
  •  粉色の甜心
    2021-01-26 11:34

    Ok, I think I figured it out (at least partially**). I believe I was getting the error because what I had was really just not correct syntax for a Linq query--that is I was trying to use a list member in a query on a table that it didn't exist in (maybe?)

    Correcting the syntax I was able to come up with this, which works for my current purposes. The downside is that it's only sorting by the first item in the link. I'm not sure how you'd do this for multiple items--would be interested to see if anyone else has thoughts

    dataIQ = dataIQ.OrderByDescending(d => d.Quotes.FirstOrDefault().QuoteName);
    

    **Edit: confirmed this is only partially fixing my issue. I'm still getting the original error if I try to access a child object of Quotes. Anyone have suggestions on how to avoid this error? The below example still triggers the error:

     IQueryable dataIQ = _context.Data
            .Include(d => d.Quotes).ThenInclude(q => q.Owner)
            .Include(d => d.Location);
    
    dataIQ = dataIQ.OrderByDescending(d => d.Quotes.FirstOrDefault().Owner.OwnerName);
    

提交回复
热议问题