linq - How can I do an OrderBy with a dynamic string parameter? -
i want this:
var orderby = "nome, cognome desc"; var timb = time.timbratures.include("anagrafica_dipendente") .where(p => p.coddipendente == 1); if(orderby != "") timb = timb.orderby(orderby);
is there orderby
overload available accepts string parameter?
absolutely. can use linq dynamic query library, found on scott guthrie's blog. there's updated version available on codeplex.
it lets create orderby
clauses, where
clauses, , else passing in string parameters. works great creating generic code sorting/filtering grids, etc.
var result = data .where(/* ... */) .select(/* ... */) .orderby("foo asc"); var query = dbcontext.data .where(/* ... */) .select(/* ... */) .orderby("foo ascending");
Comments
Post a Comment