我有一個SQL查詢,它選擇前5000個數(shù)據(jù),并有一些條件?,F(xiàn)在我的問題是,如何從實(shí)體框架編寫相同的查詢?可能嗎?我想知道從實(shí)體框架實(shí)現(xiàn)此查詢的最有效方法。查詢: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# 實(shí)體:using (var ctx = new db_ProductionEntities()){ //var items = ctx.MyData.Take(10).ToList(); need to know how to write query here}
1 回答

揚(yáng)帆大魚
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超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 關(guān)注
- 119 瀏覽
添加回答
舉報
0/150
提交
取消