LINQ EF Присоединяйтесь с добавленным CROSS JOIN - PullRequest
1 голос
/ 01 ноября 2011

Этот синтаксис linq to ef создает синтаксис sql, показанный ниже. Как я могу заставить его производить без CROSS JOIN? Перекрестное соединение дает мне кучу дополнительных записей.

vehicleList = (from _vehicle in shireyContext.Vehicles
                                   join _statusDescription in shireyContext.StatusDescriptions
                                   on _vehicle.Status equals _statusDescription.StatusId
                                   join _newOptions2 in shireyContext.VehicleOption_New
                                   on _vehicle.StockNo equals _newOptions2.StockNo
                                   where _vehicle.NewOrUsed == NewOrUsed && _vehicle.Model == Model && _newOptions2.Color != null                                       
                                   from _newOptions in shireyContext.VehicleOption_New
                                   select new VehicleDomainEntity
                                   {
                                       StockNo = _vehicle.StockNo,
                                       Year = _vehicle.VehicleYear,
                                       Make = _vehicle.Make,
                                       Model = _vehicle.Model,
                                       Description = _newOptions2.Description,
                                       ExteriorColor = _vehicle.ExteriorColor,
                                       InteriorColor = _vehicle.InteriorColor,
                                       InternetPrice = _vehicle.CodedCost,
                                       ListPrice = _vehicle.ListPrice,
                                       Status = _statusDescription.StatusDescriptionText,
                                       NewOrUsed = _vehicle.NewOrUsed,
                                       Mileage = _vehicle.Mileage,
                                       VIN = _vehicle.VIN
                                   }).ToList();

производит этот sql:

 SELECT
Extent2.StatusId AS StatusId,
Extent1.StockNo AS StockNo,
Extent1.VehicleYear AS VehicleYear,
Extent1.Make AS Make,
Extent1.Model AS Model,
Extent3.Description AS Description,
Extent1.ExteriorColor AS ExteriorColor,
Extent1.InteriorColor AS InteriorColor,
Extent1.CodedCost AS CodedCost,
Extent1.ListPrice AS ListPrice,
Extent2.StatusDescriptionText AS StatusDescriptionText,
Extent1.NewOrUsed AS NewOrUsed,
Extent1.Mileage AS Mileage,
Extent1.VIN AS VIN
FROM  dbo.Vehicles AS Extent1
INNER JOIN dbo.StatusDescription AS Extent2 ON Extent1.Status = Extent2.StatusId
INNER JOIN dbo.VehicleOption_New AS Extent3 ON Extent1.StockNo = Extent3.StockNo
CROSS JOIN dbo.VehicleOption_New AS Extent4
WHERE (Extent1.NewOrUsed = 'N') AND (Extent1.Model = 'cts' AND (Extent3.Color IS NOT NULL))

1 Ответ

0 голосов
/ 01 ноября 2011

Я думаю, вы хотите это

from _vehicle in shireyContext.Vehicles
join _statusDescription in shireyContext.StatusDescriptions
on _vehicle.Status equals _statusDescription.StatusId
join _newOptions2 in shireyContext.VehicleOption_New into VehicleNew
on _vehicle.StockNo equals _newOptions2.StockNo
where _vehicle.NewOrUsed == NewOrUsed && _vehicle.Model == Model && _newOptions2.Color != null
from _newOptions in VehicleNew

Две измененные строки:

 join _newOptions2 in shireyContext.VehicleOption_New into VehicleNew

и

from _newOptions in VehicleNew
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...