Search code examples
c#linqexpressionlinq-expressionsexpressionvisitor

Can we delete clauses from linq expression?


I was wondering whether it's possible to add/remove a where clause from a linq expression/ query operators.

Eg :-

var qry = from e in emp where(e => e.salary > 5000) select e;

Is it possible to remove where expression at a later stage?

Thanks in advance :)


Solution

  • Yes, it is possible, but you need to implement an ExpressionVisitor class to evaluate the composite expression and change it according to your needs. Unless you are doing something relatively complex there is probably a better way to accomplish what you want.