gpt4 book ai didi

c# - 如何在 Entity Framework 查询中使用左连接?

转载 作者:太空宇宙 更新时间:2023-11-03 19:09:48 24 4
gpt4 key购买 nike

<分区>

我正在使用 Entity Framework 4.5。我必须将 SQL 查询转换为实体查询:

SELECT Customer.CustCode, Invoice.InvoiceId, Invoice.BatchNumber, Invoice.InvoiceDate, Invoice.AdjustFlag, Invoice.InvoiceAmount,
Invoice.InvoiceNote, Invoice.AmountPaid, Customer.BillingContact, Customer.BillingCompany, Customer.BillingStreet1,
Customer.BillingStreet2, Customer.BillingCity, Customer.BillingState, Customer.BillingZip, [Order].PickupDate, [Order].OrderNumber,
[Order].OrderTotal, [Order].ProNumber, [Order].PickupCompany, [Order].PickupCity, [Order].PickUpState, [Order].Dcompany,
[Order].Dcity, [Order].Dstate, CONVERT(varchar(5), DeliverInTime, 114) AS DelInTime, [Order].PiecesWeight1, [Order].BaseRATE,
[Order].POD, [Order].Requester, [Order].Po1, [Order].Po2, AccessorialCharge.Description,
OrderDriverExtraCharge.AccessorialChargeDesc, OrderDriverExtraCharge.AccessorialChargeAmount, [Order].NormalDiscount,
- 1 * [Order].DISCAmount AS DISCAmount
FROM (((Invoice INNER JOIN
[Order] ON Invoice.InvoiceId = [Order].InvoiceId) INNER JOIN
Customer ON Invoice.CustID = Customer.CustID) LEFT JOIN
OrderDriverExtraCharge ON [Order].OrderNumberId = OrderDriverExtraCharge.OrderNumberId) LEFT JOIN
AccessorialCharge ON OrderDriverExtraCharge.AccessorialChargeId = AccessorialCharge.AccessorialChargeId
where Invoice.InvoiceId = '1117782'

如果我将 OrderDriverExtraCharge.OrderNumberId) LEFT JOIN 更改为 OrderDriverExtraCharge.OrderNumberId) JOIN(简单连接)或内部连接,它不会显示正确的结果。

我试过这个:

from I in db.Invoices
join O in db.Orders on I.InvoiceId equals O.InvoiceId
join C in db.Customers on I.CustId equals C.CustId
join OD in db.OrderDriverExtraCharges on O.OrderNumberId equals OD.OrderNumberId
join AC in db.AccessorialCharges on OD.AccessorialChargeId equals AC.AccessorialChargeId
where I.InvoiceId == invoice.InvoiceId
select new PrintInvoiceViewModel()

但它没有显示所需的结果。请帮助我,如果它对我有用,我会标记你的答案。谢谢。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com