我有这样的代码:
//build query
var shops = (from p in dataContext.shops
let distance = dataContext.GetDistance(p.lat, p.lon, nearlat,nearlon)
join c in dataContext.shops_category on p.id equals c.poi_id
select new ShopsModel { p = p, distance = distance }
);
}
//add dynamic orderby
if(somthig)
shops.OrderBy(distance)
else
shops.OrderBy(p.name)
//get records.
return shop.Take(30).ToList()
除了 OrderBy,它工作正常。生成的 SQL 代码不包含 orderby 子句,记录未排序。
任何的想法?感谢帮助。