我有两张桌子:
ProductCodes
:
Code Year PageNo
-----------------------------------------
和Costs
:
Code Year City QsNo price
----------------------------------------------------------------
我想保留特定的所有代码,year-pageNo
然后显示特定的成本year-city-Qsno
(如果存在)和不存在的成本,我返回 null。
我写了这个查询:
var Result = from code in ent.ProductCodes
join cost in ent.Costs
on new { a = code.Year, b = code.Code } equals new { a = cost.Year, b = cost.Code }
into AllCosts
from OutPut in AllCosts.DefaultIfEmpty()
where code.PageNo == PageNo && OutPut.Year == Year && OutPut.City == City && OutPut.QsNo == Qsno
select new
{
ProductCode = code.Code
Col6 = OutPut.Price
};
但它转换为INNER JOIN
。问题出在哪里?