Reputation: 87
I need to search if a decimal (converted to string) is contained in another decimal (also converted to string) in a linq query so if I filter for 09
in {12309123, 000999, 123459}
i find only the first two "elements" (12309123 and 000999).
so far I tried with:
query = query.Where(x => x.DecimalProp.ToString().Contains(filtri.DecimalProp.ToString()));
but when i try to do query.toList()
it throws a System.NotSupportedException ("Too many characters in character literal"). I looked on the internet but I didn't find anything useful.
Any ideas?
Upvotes: 1
Views: 552
Reputation: 56688
Linq to EF does not support method ToString
called on an arbitrary object. If you want to do such a convertion in the query, you can use SqlFunctions class. This class provides a range of static functions for various sql operations, including a fucntion for converting decimal to string:
query = query.Where(x => SqlFunctions.StringConvert(x.DecimalProp).Contains(SqlFunctions.StringConvert(filtri.DecimalProp));
Upvotes: 3