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

前端 未结 6 1983
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 02:17

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.

publ         


        
6条回答
  •  时光说笑
    2020-12-04 02:24

    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 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();
     }
    

提交回复
热议问题