0
LINQPadで期待通りに機能するデータを取り出すためにlinqに変換した継承したSQLのビューコードを持っていますが、それをC#ソリューションに転送するとサブコレクション読み込まれません。特にフレームワーク内のNULLサブコレクション
var query = from poh in _pckOrderHeadeRepository.GetAllIncluding(pd => pd.PckOrderDetail)
join mcs in _mstrConsigneeShipToRepository.GetAll() on poh.RouteId equals mcs.Consignee
//select new {poh, mcs}; //works
join det in (
from d in _pckOrderDetailRepository.GetAllIncluding(pd=> pd.PckOrderHeader, pd => pd.MstrSku)
join s in (
from shpCartonHeader in _shpCartonHeaderRepository.GetAll()
group shpCartonHeader by new
{
shpCartonHeader.OrderNum
}
into g
select new
{
g.Key.OrderNum,
CartonWeight = g.Sum(p => p.TotalWeight)
}) on d.PckOrderHeader.OrderNum equals s.OrderNum into sJoin
from s in sJoin.DefaultIfEmpty()
group new {d.PckOrderHeader, d, d.MstrSku, s} by new
{
d.PckOrderHeader.OrderNum
}
into g
select new
{
g.Key.OrderNum,
OrderQty = g.Sum(p => p.d.OrderQty),
OrderWeightOpen = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("OPEN")).Sum(p => p.d.MstrSku.Weight * p.d.OrderQty),
OrderWeightReleased = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("RELEASED")).Sum(p => p.d.MstrSku.Weight * p.d.PickingQty + p.s.CartonWeight),
OrderWeightPacked = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("PACKED")).Sum(p => p.s.CartonWeight),
PrePack = g.Max(p => p.d.MstrSku.Prepack)
}) on poh.OrderNum equals det.OrderNum
join toa in _shpTrailerOrderAssignmentRepository.GetAll() on poh.OrderNum equals toa.OrderNum into
toaJoin
from toa in toaJoin.DefaultIfEmpty()
select new
{
det,
poh,
toa,
mcs
};
この部分:例えばこのため
select new
{
g.Key.OrderNum,
OrderQty = g.Sum(p => p.d.OrderQty),
OrderWeightOpen = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("OPEN")).Sum(p => p.d.MstrSku.Weight * p.d.OrderQty),
OrderWeightReleased = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("RELEASED")).Sum(p => p.d.MstrSku.Weight * p.d.PickingQty + p.s.CartonWeight),
OrderWeightPacked = (decimal?)g.Where(p => p.d.PckOrderHeader.OrderStat.Equals("PACKED")).Sum(p => p.s.CartonWeight),
PrePack = g.Max(p => p.d.MstrSku.Prepack)
}) on poh.OrderNum equals det.OrderNum
:
PrePack = g.Max(p => p.d.MstrSku.Prepack) // MstrSku is not loaded
とp.d内部プロパティ(PckOrderDetail)
public virtual MstrSku MstrSku { get; set; }
linqpadの同等のクエリが正しく動作するので、LINQPadsの動作を模倣するためにサブプロパティを適切に読み込むために何が欠けているのだろうかと思っています。
下のサンプルのように最初の行でそれを使用し、このEFコアですか? – aaron
はいこれはEFCore 2.0.1、ASPNET Zero 4.6.0.0 – rigo
です。これはEFコアの制限です。https://stackoverflow.com/questions/40380621/include-not-working-with-joinentity – aaron