[英]How to use “AND” in Entity Framework under the same column
I have been looking for a way to retrieve some specific information from a table but it's nor retrieving any result, I am using Entity Framework and C#. 我一直在寻找一种从表中检索某些特定信息的方法,但是它也没有检索任何结果,我正在使用Entity Framework和C#。
var plans = (
from p in context.AirTables
where p.eflID == 536 && p.eflID == 537
select p)
.ToList();
The if (plans.Count() != 0)
is giving me 0 as value, and I am 100% sure that the information which I am retrieving is correct. if (plans.Count() != 0)
给我0作为值,我100%确定我要检索的信息是正确的。
Can somebody help me out? 有人可以帮我吗?
Thanks in advance 提前致谢
Your are probably trying to retrieve the AirTables
that cointain in the column eflID
either 536
or 537
values. 您可能正在尝试检索在
AirTables
列中eflID
536
或537
值的eflID
。 You could do it in several ways. 您可以通过几种方式做到这一点。
int[] ids = new int[] { 536, 537};
var plans = context.AirTables.Where(x=> ids.Contains(x.eflID)).ToList();
or 要么
var plans = context.AirTables.Where(x=> x.eflID ==536 || x.eflID == 537).ToList();
the first one should translate into ... where eflID in (536, 537)
and the second one into ... where eflID=536 OR eflID = 537
第一个应转换为
... where eflID in (536, 537)
第二个应转换为... where eflID in (536, 537)
... where eflID=536 OR eflID = 537
您需要使用OR
而不是And
检查
var plans = context.AirTables.Where(x=> x.eflID ==536 || x.eflID == 537).ToList()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.