Centralize Repository Lambda Code

Aug 3, 2012 at 10:06 AM

Hi all,

Suppose i have a code that retrieve users with some logic, i use it in front and back office.

for example : userRepo.Find(u => u.id == id && u.status == status) ;
Is it possible to centralize this code somewhere ? 
so the code will be like this userRepo.Find(userLambda);

I am new with lambda expressions so i don"t know if this is possible or not


Thanks for help

Aug 19, 2012 at 11:01 PM
Edited Aug 19, 2012 at 11:10 PM

Hi riadhgomri,

yes, you can store a lambda like any other variable :

Expression<Func<User, bool>> _myPredicate = u => u.id == id && u.status == status;

and then use it like that :


I hope this will help you.