I'm using EF6 code first with System.Dynamic.Linq. I'm trying to figure out how to cast string to decimal. Basically the same as was requested here: Dynamic LINQ Cast issue
My system parses files that generate Name/Value pairs. These are stored in a table as varchar columns. The values could represent any type (string, int, decimal, datetime, etc.) so I can't really save to the actual data type, hence the reason everything is stored as varchar.
I have a textbox in the application that lets the user enter a dynamic linq query. For instance, a user might be attempting to do this:
Name == "Test Value" && Value > 5.5
or
Name == "Other Value" && Value == "My String Value"
The problem is I can't seem to do the cast necessary on the Value column. I'm mainly interested in converting to decimal for the moment since that's what most of the data is. I've tried a number of suggestions I've found out there:
- Convert.ToDecimal(Value): Linq to Entities does not recognize the method
- Decimal.Parse(Value): Linq to Entities does not recognize the method
- Tried implementing a DbFunction (Example). Converted it to be decimal instead of int. ParseDecimal(Value): No applicable method exists. And apparently it's looking for that method on the business object itself.
Seems like a simple and common thing to need to do. What am I missing?