0

我还是 LINQ 的新手。这种情况可能与linq有关吗?

我有 4 张桌子:

1. Garage (ID, Name)
2. Car (ID, GarageID, Name) -- a garage has multiple cars.
3. Dealer (ID, Name)
4. Car_Dealership (ID, CarID, DealerID) -- many to many table between car and dealer

我想收集所有车库以及每个车库处理的每个经销商。

你怎么能用 LINQ 做到这一点?

提前致谢!

4

1 回答 1

0

你应该能够使用这样的东西:

var map =
  from garage in Garages
  join car in Cars on garage.ID equals car.GarageID
  join car_dealership in Car_Dealerships on car.ID equals car_dealership.CarID
  join dealer in Dealers on car_dealership.DealerID equals dealer.ID
  group dealer by garage;

foreach (var garage in map)
{
  Console.WriteLine("Garage: " + garage.Key.Name);

  foreach (var dealer in garage)
    Console.WriteLine("  Dealer: " + dealer.Name);
}

将来,请发布您尝试过的内容,以便我们可以帮助您解决遇到的具体问题。

于 2013-09-24T21:38:31.137 回答