【发布时间】:2010-12-20 09:40:43
【问题描述】:
您好,我在使用 Linq to Entities 获得的 IQueryable 对象的 Where 子句扩展方法中使用 bool 操作时遇到了一些问题。第一个示例显示了使用 Bool1 作为我需要移动到 where 子句扩展方法的操作的工作原理。第二个示例是更改后不起作用的内容。 Bool1 被完全忽略,不会影响结果。
示例 1:
var results =
from a in context.aTable1
where a.Bool1 == false && a.Bool2 == false
select new
{
Column1 = a.Column1
Bool1 = a.Bool1
Bool2 = a.Bool2
};
results.Where(l => l. Column1.Contains(fooString));
示例 2:
var results =
from a in context.aTable1
where a.Bool2 == false
select new
{
Column1 = a.Column1
Bool1 = a.Bool1
Bool2 = a.Bool2
};
results.Where(l => l.Bool1 == false);
results.Where(l => l. Column1.Contains(fooString));
这些是过度简化的示例,但我希望它们能展示我正在尝试做的事情。 where 扩展方法使用不同的方法,是我创建原始查询时无法完成它们的原因。
我已经尝试了以下其他方法来使用 where 子句做同样的事情:
results.Where(l => !l.Bool1);
results.Where(l => l.Bool1.Equals(false));
它们具有相同的效果。
【问题讨论】:
标签: c# linq .net-3.5 linq-to-entities iqueryable