tdelev
tdelev

Reputation: 863

Translate this SQL Query in LINQ to SQL

How can I write a query similar to this one in LINQ to SQL

SELECT Id, (Distance - someValue) as Res
FROM Table
WHERE Res < someOtherValue
ORDER BY Res

Upvotes: 0

Views: 214

Answers (2)

Jacob
Jacob

Reputation: 78920

If you prefer keyword-style LINQ, it'd look something like this:

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

Upvotes: 2

Andreas Grech
Andreas Grech

Reputation: 108040

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

...where 4 is your someOtherValue

Upvotes: 1

Related Questions