我正在转换旧的webforms应用程序为asp.net mvc,我有问题将我的一个sql语句转换为linq。特别是,我需要帮助分组和连接。我通过查看各种示例尝试了几种方法,但都没有为我工作。将sql转换为linq(连接和分组)
SELECT cp.PartNumber, cp.PartDescription, PFEP.PFEPTx, PFEP.KBQty,
TX_QOH.QOH, TX_ReworkQOH.Rework_QOH as Rework, SUM(ShippingInput.Qty) AS
'Ocean'
FROM CustomerParts as cp
LEFT JOIN TX_QOH
ON cp.PartNumber = TX_QOH.PN
LEFT JOIN TX_ReworkQOH
ON cp.PartNumber = TX_ReworkQOH.PN
LEFT JOIN ShippingInput
ON cp.PartNumber = ShippingInput.PN AND ShippingInput.Status <> 'Received'
LEFT JOIN PFEP
ON cp.PartNumber= PFEP.PN
WHERE cp.PartType = 'Actuator Part' AND cp.Division = 'Bayne' AND cp.Active
= 'Yes' AND TX_QOH.QOH = '0'
Group By cp.PartNumber, TX_QOH.QOH, TX_ReworkQOH.Rework_QOH,
cp.PartDescription, PFEP.PFEPTx, PFEP.KBQty
Order By cp.PartNumber ASC
格式化代码,也许? –
人们更有可能帮助修复企图翻译,而不是为您编写翻译 – jhhoff02
*不要*那样做。这是一个严重的错误。 LINQ to SQL或LINQ to Entities是ORM的查询语言,而不是SQL的替代品。不能在没有ORM的情况下使用LINQ。创建具有关系和导航属性的适当实体,并让ORM完成匹配相关行并将它们传递给对象的工作 –