我将如何在 Linq-to-SQL 查询中反转包含,以便我可以检查是否Title
或Description
包含列表中的任何单词,例如:
var query = context.Shapes.Where(x => x.Title.Contains(words));
这是我现在所拥有的,但这与我所需要的相反。
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
更新
我现在有
var query = context.Shapes.Where(x => words.Any(w => x.Title.Contains(w) || x.Description.Contains(w)))
int s = query.Count();
但现在我收到异常int s = query.Count();
消息“本地序列不能在查询运算符的 LINQ to SQL 实现中使用,但包含运算符除外。” 有谁知道如何解决它?