これが私が見つけた良いサンプルで、あなたが探しているものを説明していると思います。間違いなくJOINが必要です。
class Job
{
public int ID { get; set; }
public string Name { get; set; }
public string Title { get; set; }
}
class Sector
{
public int ID { get; set; }
public string SectorName { get; set; }
}
class City
{
public int ID { get; set; }
public string CityName { get; set; }
}
void Main()
{
var jobs = new Job[]
{
new Job{ID = 5, Name = "Sam", Title="Minion"},
new Job{ID = 6, Name = "Dave", Title="Overlord"},
new Job{ID = 7, Name = "Julia", Title="Minion"},
new Job{ID = 8, Name = "Sue", Title="Minion"}
};
// Example orders.
var sectors = new Sector[]
{
new Sector{ID = 5, SectorName = "Sector42"}
};
var cities = new City[]
{
new City{ID = 5, CityName = "TownsVille"}
};
// Join on the ID properties.
var query = from j in jobs
join s in sectors on j.ID equals s.ID
join c in cities on j.ID equals c.ID
select new { j.Name, j.Title, c.CityName, s.SectorName };
// Display joined groups.
foreach (var group in query)
{
Console.WriteLine("{0} Is a {1} in {2}, sector {3}", group.Name, group.Title, group.CityName, group.SectorName);
}
}
出力は次のようになります(foreachループから)
Sam Is a Minion in TownsVille, sector Sector42
私はこのサイトを参照しました:http://www.dotnetperls.com/join