I want to pass the sort field and direction dynamically to the LINQ to SQL codes. But I could not find the way to perform like that because if I could not write users.OrderBy(d => Field);
Is there any way to pass the dynamic field to sort? Thanks.
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);
}
}