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

关于c# - Lambda 表达式或 LINQ 中的子查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8199103/

10-13 06:03