每当添加连接时,都会添加一个新图层,这很难实现,尤其是在where动态子句中如何用一个词来概括每个连接我放置一个查询来显示查询我的意思是,我在这里使用了多个连接,每个Gwen都添加了t我希望添加或查询的每个字段都必须添加一个长字符串t我希望直接写入您为连接命名的名称
context.Trips
.GroupJoin(context.Entities, trips => trips.BeneficiaryEntitiesId, beneficiarys => beneficiarys.Id,
(trips, tripsEntities) => new { trips, tripsEntities })
.SelectMany(t => t.tripsEntities.DefaultIfEmpty(),
(t, beneficiarys) => new { t, beneficiarys })
.GroupJoin(context.Items, t => t.t.trips.ItemId, items => items.Id,
(t, tripsItems) => new { t, tripsItems })
.SelectMany(t => t.tripsItems.DefaultIfEmpty(),
(t, items) => new { t, items })
.Join(context.Entities, t => t.t.t.t.trips.CarrierEntitiesId,
carriers => carriers.Id,
(t, carriers) => new { t, carriers })
.Join(context.Vehicl, t => t.t.t.t.t.trips.VehiclId,
vehicls => vehicls.Id,
(t, vehicls) => new { t, vehicls })
.Join(context.DefineLists, t => t.vehicls.VehiclType,
vehiclsType => vehiclsType.Id,
(t, vehiclsType) => new { t, vehiclsType })
.Join(context.Drivers, t => t.t.t.t.t.t.t.trips.EntryDriverId,
endrivers => endrivers.Id,
(t, endrivers) => new { t, endrivers })
.GroupJoin(context.Drivers, t => t.t.t.t.t.t.t.t.trips.OutputDriverId,
oudrivers => oudrivers.Id,
(t, oudrivers) => new { t, oudrivers })
.SelectMany(t => t.oudrivers.DefaultIfEmpty(),
(t, oudrivers) => new { t, oudrivers })
.Where(@$"(t.t.t.vehiclsType.ListType==1 {SDateWhere}{EDateWhere})
{SubWhere}{MainWhere}", StartDate, ed)
.Select(s => new
{
s.t.t.t.t.t.t.t.t.t.trips.Id,
TripsFullNo = $"{s.t.t.t.t.t.t.t.t.t.trips.TripsFullNo} {s.t.t.t.t.t.t.t.t.t.trips.TripsNo}",
OperationTtype =
s.t.t.t.t.t.t.t.t.t.trips.Loading
? operationTtypes[s.t.t.t.t.t.t.t.t.t.trips.OperationTtype ?? 0]
: $"{Language.ListOperateTransfer} {Language.ListEmpt}",
Vehicl = $"{s.t.t.t.t.vehicls.LicensePlate}/{s.t.t.t.vehiclsType.ListItem}",
CarrierEntities = s.t.t.t.t.t.carriers.EntitieName,
BeneficiaryEntities = s.t.t.t.t.t.t.t.t.beneficiarys!.EntitieName,
Item = s.t.t.t.t.t.t.items!.NoName,
Driver = $"{s.t.t.endrivers.DriverLicense}/{s.t.t.endrivers.DriverName}"
}).OrderByDescending(o=>o.Id)
2条答案
按热度按时间hs1ihplo1#
下面是一个在创建多个连接时将深度转换为宽度的示例。请注意,正确使用EF/EF核心可以使嵌套连接变得不必要,并且更容易使用。
kx5bkwkv2#
通过创建一个扩展方法来表示
LeftJoin
(这需要对结果使用已知的类),您可以将GroupJoin
和SelectMany
操作与一些次要的命名问题结合起来。给定: