This is not about the reuse of a result but more the statement itself. Nor is it about an error when using var as mentioned in: LINQ to SQL: Reuse lambda expression
Out of sheer curiosity I was wondering if it is possible to reuse a single LINQ statement.
Lets say I have the following LINQ statement:
.Where(x => x.Contains(""));
Is it possible to extract the statement x => x.Contains("")
and use some kind of reference to this for later usage in, lets say, another class?
So I can call it like: .Where(previouslySavedStatement);
Func<string, bool> func = x => x.contains("");
– WeldFunc<string, bool> previouslySavedStatement = x => x.Contains("")
orExpression<Func<string, bool>>
if the source is anIQueryable
. – ChristanExpression<Func<Table1, bool>> lambda = x => x.Id > 1000;
andFunc<Table1, bool> lambda = x => x.Id > 1000;
for IEnumerables which is the same as the answer you marked correct. The "base" is the same. IEnumerables take lamdas/delegates, while IQueryables take expressions to build expression trees. – Tanbark