我们需要查询 数据表 TableA 中 字段 Age(int) 的值 在 一个给定集合 中的纪录
用Sql 表示就是
Select * from TableA where Code in ('A','B','C')
那么如何使用 Linq to Entity 来实现此操作呢
List
using(DBContext context=new DBContext)
{
var query=from m in context.TableA
where codeSet.Contains(m.Age)
select m;
.......
}
总结:
类似问题可以 首先建立一个 List
使用 Contains方法来判断 实体的属性值是否在 此集合中
需要查询数据表TableA 中字段Age(int)的值在一个给定集合中的纪录
用Sql 表示就是
Select * from TableA where Code in ('A','B','C')
那么如何使用 Linq to Entity 来实现此操作
List
using(DBContext context=new DBContext)
{
var query=from m in context.TableA
where codeSet.Contains(m.Age)
select m;
.......
}