Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
添加交叉联接的LINQ EF联接_Linq_Entity Framework_Join - Fatal编程技术网

添加交叉联接的LINQ EF联接

添加交叉联接的LINQ EF联接,linq,entity-framework,join,Linq,Entity Framework,Join,此linq to ef语法生成如下所示的sql语法。如果没有交叉连接,我如何才能使其产生?交叉连接给了我很多额外的记录 vehicleList = (from _vehicle in shireyContext.Vehicles join _statusDescription in shireyContext.StatusDescriptions on _v

此linq to ef语法生成如下所示的sql语法。如果没有交叉连接,我如何才能使其产生?交叉连接给了我很多额外的记录

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))
我想你想要这个

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


我的错!有个打字错误。请注意,我加入了newOptions 2,然后从newOptions中选择。最后一个不应该在那里。谢谢你的建议
from _newOptions in VehicleNew