2
我想將排序字段和方向動態地傳遞給LINQ to SQL代碼。但我找不到像那樣執行的方式,因爲如果我不能寫 users.OrderBy(d =>Field);LINQ to SQL動態排序
有沒有辦法通過動態字段進行排序?謝謝。
private static IQueryable<user> GetUserData(String Field, String Direction)
{
UserDataContext dc = new UserDataContext();
var users = from d
in dc.users
orderby Field ascending
select d;
if (Direction == "ascending")
{
return users.OrderBy(d => d.userName);
}
else
{
return users.OrderByDescending(d => d.userName);
}
}