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