System.Linq.Dynamic.Core
System.Linq.Dynamic.Core copied to clipboard
Recommended tool for producing Dynamic LINQ code
(Disclaimer: I am the author of the referenced library.)
As of v. 3.4.61, the ExpressionTreeToString library can now generate C# (or VB) code leveraging Dynamic LINQ library method calls and selector syntax, from virtually any expression, and by extension, from any IQueryable:
var expr = Enumerable.Empty<Person>()
.AsQueryable()
.Where(x => x.Age <= 20)
.OrderBy(x => x != null && x.LastName != null ? x.LastName : "")
.ThenBy(x => x != null && x.FirstName != null ? x.FirstName : "")
.Expression;
Console.WriteLine(expr.ToString("Dynamic LINQ", "C#"));
/*
#EnumerableQuery<Person>.Where("Age <= 20").OrderBy("np(LastName, \"\")").ThenBy("np(FirstName, \"\")")
*/
I think this would be extremely valuable in porting over code from standard LINQ to using the Dynamic LINQ library, particularly when some additional customization for Dynamic LINQ is needed.
May I suggest adding a reference to my library/NuGet package from the documentation?