5
我有這樣的代碼:LINQ - 動態排序依據條款不起作用
//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()
它工作得很好,除了排序依據。生成的SQL代碼不包含orderby子句,並且記錄沒有排序。
任何想法?感謝幫助。