I have a Linq Expression, which may be altered depending on certain conditions. An example of what I would like to do (left blank the bit I am not sure about):
If you Get
method retrives the data and returns in memory objects the you could do so
Expression> filter = (Project p) => p.UserName == "Bob";
if(showArchived) {
filter = (Project p) => p.UserName == "Bob" && p.Archived;
}
IEnumerable projects = unitOfWork.ProjectRepository.Get(filter);
EDIT
Just to point out. When you use .ToList()
method it enumerates the Queryable
, i.e. makes a database request.