I don't understand why my variable selected
doesn't contain the content of all the TempX
variable. For example, in my case, the variable TempX
containt one SuperObject but as soon as I reach the first intersect, it's lost and my View always show an empty list...
By the way, the blablabla.ToList() are real and complicated linq query. I put this to make it clearer.
Thanks and here is the code:
public ActionResult Search(string q)
{
ViewBag.q = q;
String[] strQueries = q.Split(' ');
IEnumerable<SuperObject> selected = new List<SuperObject>();
foreach (string str in strQueries)
{
//Query 1
IEnumerable<SuperObject> Temp1 = blablabla.ToList();
//Query 2
IEnumerable<SuperObject> Temp2 = blablabla2.ToList();
//Query 3
IEnumerable<SuperObject> Temp3 = blablabla3.ToList();
//Query 4
IEnumerable<SuperObject> Temp4 = blablabla4.ToList();
selected = selected.Intersect(Temp1);
selected = selected.Intersect(Temp2);
selected = selected.Intersect(Temp3);
selected = selected.Intersect(Temp4);
}
return View("Search", selected);
}
You probably want to use Union
instead of Intersect
. Here's the difference, I think it's self explanatory:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With