Reputation: 1631
I have to filter data based on Dates passed Parameters: StartDate, EndDate with default value null.
Filter:
If both Dates passed then return record between dates.
var appointmentNoShow = _db.Appointments Where (x=> s.appointmentDate ?? ).ToList();
So I need separate queries or I can do with some condition in one query.
Upvotes: 0
Views: 259
Reputation: 1619
You'd want to write a series of if statements to handle this.
if(StartDate == SomeDate && EndDate == Somdate)
{
return ALL Records after start date but before enddate
}
else if(StartDate == SomeDate && EndDate == Null)
{
return all records after StartDate
}
else if(StartDate == null && EndDate == SomeDate )
{
return all records before EndDate
}
else
{
Return all records
}
this is the most basic way to represent this. You can of course clean this up and use conditionals in a different way, but this is about as basic an example you can get, so feel free to tweak it anyway you want.
Upvotes: 0