Lambda表达式或LINQ中的子查询

时间:2011-11-20 02:50:13

标签: c# linq lambda

如何使用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

2 个答案:

答案 0 :(得分:7)

对您的模型了解不多,这里是您查询的盲机械翻译:

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)

答案 1 :(得分:2)

where Dealers.Any(d => d.Account == "UCERT" && something.StockNo == d.StockNo)