Krishna Ballavi  Rath
Krishna Ballavi Rath

Reputation: 302

LINQ to Entities does not recognize the method 'System.String ToString()' method,and this method cannot be translated into a store expression

allList = allList.Where(c => isAdvertSearchable 
  && c.tblAdvert.AdvertTitle.ToLower().Trim().Contains(param.sSearch.ToLower())
  || isTranastionTypeSearchable 
  && c.IsActive.ToString().ToLower().Trim().Contains(param.sSearch.ToLower())
  || (c.Amount.ToString().ToLower().Contains(param.sSearch.ToLower().ToString()) 
  || param.sSearch == "")
  || isTranastionIDSearchable 
  && c.TransactionId.ToLower().Trim().Contains(param.sSearch.ToLower())

Upvotes: 1

Views: 404

Answers (1)

Mihai Dinculescu
Mihai Dinculescu

Reputation: 20033

LINQ is complaining about not being able to translate ToString to T-SQL.

Use

SqlFunctions.StringConvert(param.sSearch.ToLower())

SqlFunctions Class
Provides common language runtime (CLR) methods that call functions in the database in LINQ to Entities queries.
http://msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions(v=vs.110).aspx

Upvotes: 1

Related Questions