–Cross Join:
//LINQ Query Example For Cross Join
//This joins elements of two sequences based on equality of an element
public static void RiderBikeCrossJoinQuery()
{
//create a string array
string[] bikeWinners = new string[] {
“Honda”, “Yamaha”
};
//populate the Generic List
createRiders();
var linqQuery =
from w in bikeWinners
join r in riderList on w equals r.BikeMake
select new { Winner = w, r.BikeModel, r.FirstName, r.LastName };
foreach (var win in linqQuery)
{
Console.WriteLine(“Winner is {0} {1} on the {2} from {3} “, win.FirstName,
win.LastName,
win.BikeModel, win.Winner);
win.BikeModel, win.Winner);
}
Console.ReadLine();
}
–Group Join:
//LINQ Query Example for Group Join
//This joins riders that have the same BikeMake
public static void RiderBikeGroupJoinQuery()
{
//create a string array
string[] bikeMake = new string[] {
“Yamaha”, “Ducati”
};
//populate the Generic List
createRiders();
var linqQuery =
from b in bikeMake
join r in riderList on b equals r.BikeMake into bm
select new {Bikes = b, Models = bm}
;
foreach (var m in linqQuery)
{
Console.WriteLine(m.Bikes + “:”);
Console.WriteLine(“——————–“);
foreach (var x in m.Models)
{
Console.WriteLine(x.BikeModel);
}
Console.WriteLine();
}
Console.ReadLine();
}