Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ToString() method to convert an integer to string inside LINQ

When I try to use ToString() inside the below LINQ Lambda expression, I get an exception saying "LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression."

query = query.Where(q => q.date.ToString().Contains(filtertext)
                          || q.invoicenum.ToString().Contains(filtertext)
                          || q.trans_type.ToString().Contains(filtertext)
                          || q.charge.Contains(filtertext));

I am using Linq to entites. And the Database used is MySQL and not the SQL Server. Immediate help would be highly appreciated.

like image 569
CHash_Mike Avatar asked Dec 19 '25 05:12

CHash_Mike


1 Answers

I resolved this issue by directly writing MySQl query inside C# as below -

string queryTemplate = 
 @"select inv.* from invoices as inv where userID = '123' and date like '%abc%'";
List<invoice> totalSearch = 
 context.ExecuteStoreQuery<invoice>(queryTemplate).ToList();
like image 112
2 revs, 2 users 80%TJB Avatar answered Dec 20 '25 17:12

2 revs, 2 users 80%TJB