Language Support for Combining Expressions? #5189
-
Maybe I'm missing something but it seems like it should be really easy to combine expressions or use them as sub expressions. How would I do this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I haven't tried this, but it seems like it could work: public Task RemapUsers(Expression<Func<User, string>> expression)
{
var predicate = Expression.Lambda<Func<User, bool>>(
Expression.Equal(expression.Body, Expression.Constant("Hello")),
expression.Parameters);
var Data = DbContext.Set<User>().Where(predicate).ToList();
} The general case of inlining an expression like this seems like it involves creating a new tree by rewriting the |
Beta Was this translation helpful? Give feedback.
-
You can use LINQKit for this: var Data = DbContext.Set<User>().AsExpandable().Where(x => expression.Invoke(x) == "Hello").ToList(); Considering that LINQKit exists and that this is a niche use case, I don't think it makes sense to add language support for this. |
Beta Was this translation helpful? Give feedback.
You can use LINQKit for this:
Considering that LINQKit exists and that this is a niche use case, I don't think it makes sense to add language support for this.