❔ Anonymous function in LINQ Select
I have a code as following:
Is there a way to somehow pass just the LINQ Max/Min/Average function so I don't have to repeat the rest?
15 Replies
chat gpt answer
Is this EF?
Yes, EF6
then no, you have to repeat it
actually no wait
The chatgpt won't work? It looks promising
lmao no I have no idea what that does
EF can't translate arbitrary function invocations regardless
maybe, but it might would want to work with queryGroup.ToList(), not just queryGroup
this might work
probably not though
it might
It would work on IEnumerable/List but certainly not on IQueryable
Thing is that EF makes it difficult to factor out selectors and whatnot because it has to be able to translate the entire query.
I cast it to List anyways, so I think it might be okay to just do these Max/Min/Avg on the list instead in the query?
Or I can do all 3 at the same time, but I really need just one of these based on the conditions so I was thinking it would cost performace for nothing.
I'm no EF expert but I don't think you want to call
.ToList()
if you're gonna do more filters/maps on it.Yea because after the
.ToList()
it won't be a SQL Query but just the LINQ filtering which is perhaps slowerwon't necessarily be slower, just won't act towards the database
.ToList()
executes the query synchonously and returns a list.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.