How do you check if a string contains any strings from a list in Entity Framework?

后端 未结 4 452
半阙折子戏
半阙折子戏 2020-12-06 06:38

I am trying to search a database to see if a string contains elements of a list of search terms.

var searchTerms = new List { \"car\", \"232\"          


        
4条回答
  •  抹茶落季
    2020-12-06 06:55

    You could use the Any function from Linq to see if any term is contained into the data.

    var result = context.Data.Where(data => searchTerms.Any(term => data.Name.Contains(term) ||
                                            searchTerms.Any(term => data.Code.Contains(term));
    

提交回复
热议问题