如何多次使用LINQ对数据进行排序?我试过跟随,但它只是返回所有客户。
var query = this.dbContext.Customers;
if (!string.IsNullOrEmpty(sortFilterName))
{
query.Where(q => q.Name.Equals(sortFilterName));
}
if (!string.IsNullOrEmpty(sortFilterAddress))
{
query.Where(q => q.Adress.Equals(sortFilterAddress));
}
return query.ToList();
答案 0 :(得分:3)
您需要将query
变量分配给过滤结果:
var query = this.dbContext.Customers;
if (!string.IsNullOrEmpty(sortFilterName))
{
query = query.Where(q => q.Name.Equals(sortFilterName));
}
if (!string.IsNullOrEmpty(sortFilterAddress))
{
query = query.Where(q => q.Adress.Equals(sortFilterAddress));
}
return query.ToList();