I have a block of code where a piece of the lambda expression is used again and again. How can store this logic so that i can reuse this expression piece?
Eg: lets take
The easiest way is to reuse a single lamda expression, like so:
Expression> KeysMatch =
map => map.User.Key == _users.PublicUser.Key
|| map.User.Key == _users.CurrentUser.Key;
Session.Query()(dimgroup=>(
dimgroup.Users.Where(KeysMatch)
.Where(map => map.AccessLevel.ToAccessLevel() == AccessLevel.Write))
.Count() > 0
));
The next step up is to actually modify expression trees themselves by invoking lambda expressions. This is more complicated, and unless you want to get down and dirty with it is easier with a toolkit. I suggest LinqKit.