【问题标题】:Linq to Entities - SQL “IN” clause for integer column [duplicate]Linq to Entities - 整数列的 SQL“IN”子句 [重复]
【发布时间】:2018-04-22 21:18:45
【问题描述】:
Select * From Employee where Id in (1, 2, 5, 7)

现在如何使用from where select 在 LINQ 查询中编写此代码

var ids = new List<int>() {1, 2, 5, 7}    
from employees in _EmployeeRepository.Table
where employees.id *in list*
select employess

如果字符串包含会做。如何实现整数列。我知道我缺少非常基本的东西。

【问题讨论】:

  • 为什么Contains 不适用于整数列?
  • 在 where 条件下使用 ids.Contains()。

标签: c# .net entity-framework linq


【解决方案1】:
var ids = new List<int>() {1, 2, 5, 7}    
var result = from employee in _EmployeeRepository.Table
where ids.Contains(employee.id)
select employee;

【讨论】:

    猜你喜欢
    • 2010-10-25
    • 2023-01-13
    • 2010-09-30
    • 2011-10-18
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多