I??™ve deliberately picked
two completely unrelated initial sequences to show that no matching is performed.
var query = from user in SampleData.AllUsers
from project in SampleData.AllProjects
select new { User=user, Project=project };
foreach (var pair in query)
{
Console.WriteLine("{0}/{1}",
pair.User.Name,
pair.Project.Name);
}
The output of listing 11.15 begins like this:
Tim Trotter/Skeety Media Player
Tim Trotter/Skeety Talk
Tim Trotter/Skeety Office
Tara Tutu/Skeety Media Player
Tara Tutu/Skeety Talk
Tara Tutu/Skeety Office
Figure 11.8 shows the sequences involved to get this result.
If you??™re familiar with SQL, you??™re probably quite comfortable so far??”it looks just
like a Cartesian product obtained from a query specifying multiple tables. Indeed,
most of the time that??™s exactly how cross joins are used. However, there??™s more power
available when you want it: the right sequence used at any particular point in time can
depend on the ???current??? value of the left sequence. When this is the case, it??™s not a
cross join in the normal sense of the term. The query expression translation is the
same whether or not we??™re using a true cross join, so we need to understand the more
complicated scenario in order to understand the translation process.
Before we dive into the details, let??™s see the effect it produces. Listing 11.
Pages:
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573