简体   繁体   English

如何在同一列下的实体框架中使用“ AND”

[英]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 536537值的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.

相关问题 实体框架:如何为同一个实体使用多个表? - Entity Framework: how to use multple tables for the same entity? 如何将两个外键设置为同一父列(实体框架) - How to setup two foreign keys to the same parent column (Entity Framework) 具有2个连接的实体框架在同一表上连接第1列或第2列 - Entity framework with 2 joins on same table for column 1 or column 2 如何创建临时表并在与实体框架相同的连接中使用它? - How to create a temporary table and use it in the same connection with Entity Framework? 如何在Entity Framework中的同一查询中使用Include和Anonymous Type? - How to use Include and Anonymous Type in same query in Entity Framework? 如何在Entity Framework中使用具有相同外键的多个表 - How to use multiple tables with the same foreign key with Entity Framework 如何对具有相同结构的动态表使用Entity Framework 6 LINQ查询? - How to use Entity Framework 6 LINQ query for Dynamic tables with same structure? 如何在实体框架的一列中使用具有不同数据的where子句? - How to use where clause with different data in one column in entity framework? 实体框架:如何在一列中使用两个记录 - Entity Framework: how to use two records in one column 实体框架到同一列的多个对象关系 - Entity Framework multiple object relations to same column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM