The key is to handle the empty list case in the where clause using list.Count == 0 || . This will allow you to generate the appropriate query
public List GetData(List Numbers, List Letters)
{
if (Numbers == null)
Numbers = new List();
if (Letters == null)
Letters = new List();
var q = from d in database.table
where (Numbers.Count == 0 || Numbers.Contains(d.Number))
where (Letters.Count == 0 || Letters.Contains(d.Letter))
select new Data
{
Number = d.Number,
Letter = d.Letter,
};
return q.ToList();
}
No comments:
Post a Comment