zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Executing Linq To Entities against Database with dictionary parameter doesn't work #122

Closed MichaelKastl closed 2 years ago

MichaelKastl commented 2 years ago

Whenever I try to execute a Linq to Entities query against a database using a Dictionary<string, object> as the parameter object, the query fails. I get an EvalException saying "No applicable member has been found for the expression. The error occurred for expression "." at position 3 near ".Where(x => x.Record.Proj". For one thing, my query doesn't start with a period. For another, I've tried the query with a dynamic object with named properties matching what's needed in the query, and it runs perfectly fine. It only breaks when I try to use a Dictionary<string, object>.

MichaelKastl commented 2 years ago

I realized that only eval.Execute supports a dictionary parameter. This is something you should probably put in your documentation, especially considering I couldn't even find the method in your source code to see how it was being handled.

For anyone who needs to do this in the future: use their SelectDynamic method to cast your parameters into an anonymous type. Make sure to add conversion statements into the selection string, as the parameters MUST be the correct data type for the query to succeed; Execute will do none of the conversions for you.