I have a situation where I need to apply some filters to the query, so I have a class representing the filters:
public class ReportNoteFilterDto
{
public int Year { get; set; }
public int Month { get; set; }
}
and I need to select data according this filters.
var query = _db.User;
if (filter.Month > 0 && filter.Month <= 12)
query.Select(u => new {
User = u,
Notes = u.Notes.Where(n => n.Begin.Month == filter.Month)
});
if (filter.Year > 2011)
query.Select(u => new
{
User = u,
Notes = u.Notes.Where(n => n.Begin.Year == filter.Year)
});
var results = query.Include("Notes.Foo.Bar").ToList(); //doesn't work
I need to select Notes.Foo.Bar too.
How can I do this multiple filters?
You did not assign the result of first query toqueryvariableYou can see here how a similar problem has been solved: