gpt4 book ai didi

c# - Linq-to-SQL反向包含

转载 作者:太空宇宙 更新时间:2023-11-03 18:39:12 38 4
gpt4 key购买 nike

我如何反转 Linq-to-SQL 查询中的包含,以便我可以检查 TitleDescription 是否包含我列表中的任何单词,例如:

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 实现中,但 Contains 运算符除外。”有谁知道怎么解决吗?

最佳答案

你想要

x => words.Any(w => x.Title.Contains(w) || x.Description.Contains(w))

关于c# - Linq-to-SQL反向包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10951204/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com