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

Expression is missing an 'as' clause #417

Closed
chriswarr opened this issue Sep 1, 2020 · 3 comments
Closed

Expression is missing an 'as' clause #417

chriswarr opened this issue Sep 1, 2020 · 3 comments
Assignees

Comments

@chriswarr
Copy link

For the below code I get "Expression is missing an 'as' clause" on the call to ParseLambda. This is my first time using this library so not sure if what i'm doing is ok or not?

            const string exp = @"version > new System.Version(""8.3.0.689"")";
            var p = Expression.Parameter(typeof(System.Version), "version");
            var l = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(new[] { p }, null, exp);

            var version = new System.Version("8.3.0.600");

            var result = l.Compile().DynamicInvoke(version);

@JonathanMagnan JonathanMagnan self-assigned this Sep 1, 2020
@JonathanMagnan
Copy link
Member

Hello @chriswarr ,

This library is more for LINQ Dynamic.

I might be wrong but in your case, you look more like you want a runtime compiler.

In this case, I would suggest you try our C# Eval Expression library (however, the library is not free)

Here is a working online example of what you want to try to achieve: https://dotnetfiddle.net/Ze57pA

var version = new System.Version("8.3.0.600");

// Method 1 - With Compile
const string exp = @"version > new System.Version(""8.3.0.689"")";
var compiled = Eval.Compile<Func<System.Version, bool>>(exp, "version");
Console.WriteLine(compiled(version));

// Method 2 - With Execute
Console.WriteLine(Eval.Execute(exp, new { version }));

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

@chriswarr
Copy link
Author

Ah, thanks you so much. I understand. I will check out the library. Looks perfect, I was using Roslyn for this but found it uses too much memory.

@JonathanMagnan
Copy link
Member

Hello @chriswarr ,

Don't hesitate to contact us for further assistance once you try it!

Best regards,

Jon

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