I have built a repository using Lambda expressions to filter my entity collections. As a parameter to the method I'm sending Expression<Func<Case, bool>> exp
. But inside the method I would like to update that same expression with some global filters. I can see that the expression object itself got an Update method, but I can't figure out how it is implemented (and cannot find anything while searching the net).
exp.Update(exp.Body, ???);
Could anyone give an example??
EDIT: Definition of the method: http://msdn.microsoft.com/en-us/library/ee378255.aspx
EDIT2: This is my code (where I try to use .And):
Expression<Func<Case, bool>> newExp = c => c.CaseStatusId != (int)CaseStatus.Finished
var binExp = Expression.And(exp.Body, newExp.Body);
ParameterExpression paramExp = Expression.Parameter(typeof(Expression<Func<Case, bool>>), "c");
return repository.Where(Expression.Lambda<Expression<Func<Case, bool>>>(binExp,
new[] { paramExp }).Compile()).ToArray();
It fails with the following ArgumentException: Lambda type parameter must be derived from System.Delegate
Expression(Of TDelegate)
is VB syntax. At the top of the documentation page you can switch to C#. – Merman