LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method,

c#, linq, string

Solution

For queries that do not involve too many keywords and too many rows you could implement this simple and quick solution. You can easily get around the Split function by repeatedly refining your results as follows:

 public List<TblActivities> SearchByMultipleKeyword(string keywords)
 {
     string[] keywords = pKeywords.Split(',');

     var results = Entities.TblActivities.AsQueryable();    

     foreach(string k in keywords){

         results  = from a in results
                    where a.Keywords.Contains(k)
                    select a;
     }
     return results.ToList();
 }

Problem

I am trying to implement a method where the keywords stored in the database for an activity (split by a comma) match the giving string split by a comma. ``` public List<TblActivities> SearchByMultipleKeyword(string keywords) { string[] keyword = keywords.Split(','); var results = (from a in Entities.TblActivities where a.Keywords.Split(',').Any(p => keyword.Contains(p)) select a).ToList(); return results; } ``` I am getting the following error : ``` LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method, and this method cannot be translated into a store expression. ```

Original source

Related problems