Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Produce Dynamic LINQ strings from expression trees #423

Closed
zspitz opened this issue Sep 24, 2020 · 3 comments
Closed

Produce Dynamic LINQ strings from expression trees #423

zspitz opened this issue Sep 24, 2020 · 3 comments
Assignees

Comments

@zspitz
Copy link

zspitz commented Sep 24, 2020

I've written a library producing various string representations of expression trees. I am now considering a Dynamic LINQ representation. In other words, from an expression tree like this:

Expression<Func<Person, bool>> expr = p => p.BirthDate.DayOfWeek == DayOfWeek.Tuesday

produce a string like the following:

$.BirthDate.DayOfWeek = Tuesday

Does System.Linq.Dynamic.Core have such functionality?

Also, for this purpose, where can I find the most up-to-date documentation describing the System.Linq.Dynamic.Core string syntax?

@zspitz
Copy link
Author

zspitz commented Sep 24, 2020

Something similar has been discussed in #230 .

@JonathanMagnan
Copy link
Member

Hello @zspitz ,

No, Dynamic LINQ doesn't offer this kind of feature.

Perhaps david-garcia-garcia in the mentioned issue could maybe help you more.

The most up to date documentation which has been added during the summer can be found here: https://dynamic-linq.net/overview

Best Regards,

Jon


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@zspitz
Copy link
Author

zspitz commented Oct 28, 2020

@JonathanMagnan I am very pleased to let you know that as of version 3.2, the ExpressionTreeToString library can produce corresponding Dynamic LINQ for many expressions. For example:

public class Person {
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public DateTime DOB { get; set; }
}
Expression<Func<Person, bool>> filter = p => p => 
    p.LastName == "A" || 
    p.FirstName == "B" || 
    p.DOB == DateTime.MinValue || 
    p.LastName == "C" || 
    p.FirstName == "D";
Console.WriteLine(expr.ToString("Dynamic LINQ"));
// prints:
/*
    LastName in ("A", "C") || DOB == DateTime.MinValue || FirstName in ("B", "D")
*/

Please feel free to refer to the library in help and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants