Lambda表达式或LINQ中的子查询
本文关键字:查询 LINQ 表达式 Lambda | 更新日期: 2023-09-27 18:15:10
如何使用lambda表达式或LINQ编写此查询:
SELECT *
FROM vehicles
WHERE (memo1 like '%CERTIFIED%' OR memo2 = 'CERTIFIED')
AND stockno IN (SELECT stockno FROM udealer2 where ACC='UCERT')
ORDER BY model, days DESC
不太了解你的模型,这里是你的查询的盲目机械翻译:
vehicles.Where( v =>
(SqlMethods.Like(v.memo1, "%CERTIFIED%") || v.memo2 == "CERTIFIED") &&
udealer2.Any(d => d.ACC == "UCERT" && d.stockno == v.stockno)
).OrderBy(v => v.model)
.ThenByDescending(v => v.days)
where Dealers.Any(d => d.Account == "UCERT" && something.StockNo == d.StockNo)