Linq-to-SQL反向包含

for*_*atc 1 c# linq-to-sql

我怎么会扭转在LINQ到SQL查询中包含这样我可以检查TitleDescription含有从我的列表中的任何字,是这样的:

var query = context.Shapes.Where(x => x.Title.Contains(words));
Run Code Online (Sandbox Code Playgroud)

这就是我现在所拥有的,但这与我的需要相反.

 List<string> words = Search.GetTags(q);
 //words = round,circle,square

 using(ShapesDataContext context = new ShapesDataContext())
 {
    var query = context.Shapes.Where(x => words.Contains(x.Title) || 

    words.Contains(x.Description));
 }

// Item 1: Title = Elipse , Decsription = This is not round circle
//This should be a match! but words doesn't contain 
//"This is not round circle", only round and circle so no match
Run Code Online (Sandbox Code Playgroud)

UPDATE

我现在有

  var query = context.Shapes.Where(x => words.Any(w => x.Title.Contains(w) || x.Description.Contains(w)))
  int s = query.Count();
Run Code Online (Sandbox Code Playgroud)

但是现在我得到了一个异常int s = query.Count();消息"除了Contains运算符之外,本地序列不能用于查询运算符的LINQ to SQL实现." 有谁知道如何解决它?

jas*_*son 6

你要

x => words.Any(w => x.Title.Contains(w) || x.Description.Contains(w))
Run Code Online (Sandbox Code Playgroud)