// the following approach takes sooooooo long
var result = (
from t in (
from a in ctx.t1
from b in ctx.t2
where a.id == b.id
select new { a, b }
).ToArray()
from c in ctx.t3.ToArray()
where c.name.Contains(t.a.name)
select new { t.a, t.b, c }
).ToArray();
// while the following approach takes time in seconds
var tSet = (
from a in ctx.t1
from b in ctx.t2
where a.id == b.id
select new { a, b }
).ToArray();
var cSet = ctx.t3.ToArray();
var result = (
from t in tSet
from c in cSet
where c.name.Contains(t.a.name)
select new { t.a, t.b, c }
).ToArray();
Please consider the codes above. FMPOV, these two approaches are the same as dataset (t1
& t2
) and t3
in both approaches will be evaluated before "second" where caluse is applying on to them.
However, the actual case is that the first approach is taking way so longer than second approach. May I know why?
Thanks in advance.