我有一个SQL查询,它选择前5000个数据,并有一些条件。现在我的问题是,如何从实体框架编写相同的查询?可能吗?我想知道从实体框架实现此查询的最有效方法。查询:select TOP 5000 * from MyData where Type=1 and UPC not in (select UPC from MyData where Type=2 AND UPC IS NOT NULL)C# 实体:using (var ctx = new db_ProductionEntities()){ //var items = ctx.MyData.Take(10).ToList(); need to know how to write query here}
1 回答
扬帆大鱼
TA贡献1799条经验 获得超9个赞
var answer = (from d1 in ctx.MyData
where d1.Type == 1 and
!(from d2 in ctx.MyData
where d2.Type == 2 and d2.UPC != null
select d2.UPC
).Contains(d1.UPC)
order by d1.Id //or some other field, it's needed for "Take"
select d1).Take(5000).ToList();
- 1 回答
- 0 关注
- 105 浏览
添加回答
举报
0/150
提交
取消