在Linq到实体中函数求值超时错误

本文关键字:超时 错误 函数 Linq 实体 | 更新日期: 2023-09-27 17:54:02

我使用的是框架3.5。我有一个组Linq语法如下

 var TmpClause = (from c in MES_WO_Tracking
                         join s in WorkOrders
                         on c.WoNo equals s.OrderNum
                         where s.Plant == "XX" && c.Shift != null
                         group new { 
                             c.QtyComplete,
                             c.QtyScrap
                         }
                         by new
                         {
                             MRP = s.MRP_CTLR,
                             SeqNo = c.SeqNo,
                             TriggerSAP = c.TriggerSAP,
                             Shift = c.Shift
                         } into n
                         select new BkdKPIOutput
                         {
                             MRP = n.Key.MRP,
                             SeqNo = n.Key.SeqNo + n.Key.TriggerSAP,
                             Shift = n.Key.Shift,
                             OutputQty = n.Sum(c => c.QtyComplete.Value),
                             InputQty = n.Sum(c => c.QtyScrap.Value) + n.Sum(c => c.QtyComplete.Value)
                         });

它总是给我"函数计算超时"的错误。但奇怪的是,我检查本地sql,它只花了1秒。

SELECT  [t2].[MRP_CTLR] AS [MRP] ,
    [t2].[SeqNo] + [t2].[TriggerSAP] AS [SeqNo] ,
    [t2].[Shift] ,
    [t2].[value] AS [OutputQty] ,
    [t2].[value2] + [t2].[value3] AS [InputQty] FROM    ( SELECT    SUM([t0].[QtyComplete]) AS [value] ,
                SUM([t0].[QtyScrap]) AS [value2] ,
                SUM([t0].[QtyComplete]) AS [value3] ,
                [t1].[MRP_CTLR] ,
                [t0].[SeqNo] ,
                [t0].[TriggerSAP] ,
                [t0].[Shift]
      FROM      [MES_WO_Tracking] AS [t0]
                INNER JOIN [WorkOrder] AS [t1] ON [t0].[WoNo] = [t1].[OrderNum]
      WHERE     ( [t1].[Plant] = 'XX' )
                AND ( [t0].[Shift] IS NOT NULL )
      GROUP BY  [t1].[MRP_CTLR] ,
                [t0].[SeqNo] ,
                [t0].[TriggerSAP] ,
                [t0].[Shift]
    ) AS [t2]

有人知道这个吗?非常感谢您的帮助。

在Linq到实体中函数求值超时错误

首先尝试将所有数据选择到TmpClause中,然后在另一个变量中对TmpClause数据执行group子句。虽然这不是理想的,但它可以帮助您找到导致问题的原因。