1
我試圖找到包含從數據庫歌廳他們之後的短語中所有單詞的所有元素:在LINQ奇怪的行爲爲sql
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
很快:D謝謝! – Star