Like operator or using wildcards in LINQ to Entities

前端 未结 6 1335
抹茶落季
抹茶落季 2021-02-06 05:12

I\'m using LINQ 2 Entities. Following is the problem:

string str = \'%test%.doc%\' 
.Contains(str) // converts this into LIKE \'%~%test~%.doc~%%\'
6条回答
  •  后悔当初
    2021-02-06 05:29

    So I was trying the same thing - trying to pair down a List to return all candidates that matched a SearchTerm. I wanted it so that if a user typed "Arizona" it would return everything regardless of case that had Arizona. Also, if the user typed "Arizona Cha", it would return items like "Arizona License Change". The following worked:

    private List GetCertListBySearchString()
        {
            string[] searchTerms = SearchString.Split(' ');
            List allCerts = _context.Certifications.ToList();
    
            allCerts = searchTerms.Aggregate(allCerts, (current, thisSearchString) => (from ac in current
                                                                                       where ac.Name.ToUpper().Contains(thisSearchString.ToUpper())
                                                                                       select ac).ToList());
              return allCerts;
        }
    

提交回复
热议问题