在LINQ to SQL中转换此SQL查询

时间:2009-07-03 14:49:15

标签: c# .net sql linq-to-sql

如何在LINQ to SQL

中编写类似于此查询的查询
SELECT Id, (Distance - someValue) as Res
FROM Table
WHERE Res < someOtherValue
ORDER BY Res

2 个答案:

答案 0 :(得分:2)

如果您更喜欢关键字式LINQ,它看起来像这样:

from x in theTable
where x.Distance < someOtherValue + someValue
orderby x.Distance
select new { x.Id, Res = x.Distance - someValue }

答案 1 :(得分:1)

MyTable
.Where(m => m.Res < 4)
.OrderBy(m => m.Res)
.Select(m => new {Id, Res = m.Distance - 4});

...其中4是你的someOtherValue