In standard linq when I use lambdas I can do the following:
var x = _usersService.GetAll().OrderBy(u => u.LastName).ThenBy(u => y.FirstName).ThenBy(u => u.UserId)
My question is how can I do that when I'm using System.Linq.Dynamic dll? I know I can do:
var x = _usersService.GetAll().OrderBy("LastName")
but how can I define additional order by clauses???
It's possible to build up dynamic LINQ queries or queries with several conditional criteria. In fact there are several options for doing this, including the use of expression trees.
The Dynamic LINQ library exposes a set of extension methods on IQueryable corresponding to the standard LINQ methods at Queryable, and which accept strings in a special syntax instead of expression trees.
You can use comma.
var x = _usersService.GetAll().OrderBy("LastName,FirstName,UserId")
You can also add desc
or descending
to order by descending.
var x = _usersService.GetAll().OrderBy("LastName desc,FirstName desc,UserId")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With