我的查询有问题。在我的表中,我有2个元素Active
设置为true。为了测试,我尝试只选择false元素(list应返回0个元素),但我总是得到2个元素。
域类
public Guid OrderStatusId { get; set; }
public string Name { get; set; }
public bool Active { get; set; }
public string Description { get; set; }
SQL元素
OrderStatusId = Guid.NewGuid(), Name = "xxx", Active = true, Description = "yyy"
OrderStatusId = Guid.NewGuid(), Name = "zzz", Active = true, Description = "xxx"
实体选择
public List<SlOrderStat> getDataFromSlOrderStat(string name, bool? activity)
{
activity = false;
using (var ctx = new ServisContex(conectionString))
{
var list = ctx.SlOrdersStats;
if (name != string.Empty)
list.Where(l => l.Name != name);
if (activity != null)
list.Where(l => l.Active == activity);
return list.ToList();
}
}
我做错了什么?
答案 0 :(得分:1)
你需要做
var result = list.Where(l => l.Name != name);
list.Where(...)不会影响列表本身的内容。