I have the following LINQ expression. I want calculate the sum of numeric values in an nvarchar field. I\'m using following code to do this, but I get an error
EF 5:
Instead of int.Pasrse use Convert.ToInt32. Entity Framework will generate proper CAST functions in SQL.
EF 6:
Short answer:
youEntity.Where(c=>SqlFunctions.StringConvert((decimal?)c.INTFIELD).Trim() == STRINGVALUE)
Long answer:
in EF 6 you have to convert numeric value to string with SqlFunctions.StringConvert. but it has a problem. It will add unnecessary spaces to the result. so the comparison will fail. That's why I have put Trim() there. I have tested it with EF 6.1.1.