从数据库中获取短语后,我试图找到包含短语中所有单词的所有元素:
string text = "ab cd 23";//the element prop2 must have all 3 word regardless their order
var q = from c in db.myTable
where c.Prop1 == "value"
select c;
string[] strings = text.Split(' ');
foreach(string word in strings)
{
int cnt = q.Count();//first time cnt = 1500 which is correct
q = q.Where(c => c.Prop2.Contains(word));// Prop2 is a string
cnt = q.Count();//first time cnt = 460
}
在此之前一切都很好:
foreach(string word in strings)// second time
{
int cnt = q.Count();//second time cnt = 14 ??
q = q.Where(c => c.Prop2.Contains(word));
cnt = q.Count();//first time cnt = 2
}
在第二个循环中不做任何事情,元素计数会发生变化,这应该只返回包含所有单词的元素,但它只返回最后一个元素,第三个循环是无用的,没有任何变化
我很抱歉长 Q,但我是 linq 的新手