abstract methods inside EF core queries
I'm trying to model my domain as follows
(some EF configuration stuff is left out for brevity)
I am looking to do a query like:
EF is not able to translate this query unfortunately
Is there a method to handle this? I thought about returning expression trees manually but that seems not very easy
11 Replies
I'm thinking of
but how would I use this inside an any?
EF.CompileQuery also wouldn't help me in this case I think
I'm trying to refrain from making a complex expression tree soup - even though I know that is possible
I wish to receive a query which looks like
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I can use:
Though this defeats the open-closed principle.
I would rather have each class implement their own filter expression
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
a predicate is a delegate that is equal to
Func<T, bool>
..?Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
let me try using the
Func<T, bool>
instead of an expression - but I'm pretty certain EF will refuse to attempt to translate itUnknown User•2w ago
Message Not Public
Sign In & Join Server To View
you can't translate it ever
the closest you can do is having the property return an Expression<Func<...>>
the either use a library that will take it into account
idk if
projectable
does this, it might
or like you said, construct a tree manually
there is no other way
and yes, it is quite complicated
then you have it run on the client
check you queriesUnknown User•2w ago
Message Not Public
Sign In & Join Server To View
as sure as one can be
ef core doesn't transform functions to sql
it only transforms expression trees