2012-07-12 174 views
0

我搜索與LINQ等效此查詢:相當於SQL查詢中使用LINQ

SELECT * 
FROM Shapes 
ORDER BY ABS(45.403703 - Latitude), ABS(- 71.948638 - Longitude) 

有人有一個想法?我從linq開始

回答

0
var results = 
    from x in shapes 
    orderby Math.Abs(45.403703 - x.Latitude), 
      Math.Abs(- 71.948638 - x.Longitude) 
    select x; 
2

這樣的事情?

var result = shapes 
    .OrderBy(s => Math.Abs(45.403703 - s.Latitude)) 
    .ThenBy(s => Math.Abs(-71.948638 - s.Longitude));