I need to query database and filter based on parameters passed into the function. I am passing two date parameters (used as a date range), a name, and a status parameters. All the parameters can have 'and' or 'or' conditions. Basically, I would like to build an linq expression based on which parameters are populated and pass it to Entity Framework to return a result set.
How can I do this with minimum 'if' statements? If you could be kind enough to provide an explanation with your example code, that would be awesome. I am trying to learn expression trees so an explanation would help.
At this point I don't have much code. That is why I have posted here. I can list the method signature. What exactly are you looking for?
public enum EmployeeStatus
{
FullTime,
PartTime,
Contract
}
public IEnumerable<Employee> FilterEmployees(DateTime? startDate,
DateTime? endDate, string employeeName, EmployeeStatus employeeStatus)
{ }