Я хочу передать поле сортировки и направление динамически в коды LINQ to SQL.Но я не мог найти способ так выполнить, потому что, если бы я не мог писать пользователям. OrderBy (d => Поле );
Есть ли способ передать динамическое поле для сортировки?Спасибо.
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);
}
}