Lambda .OrderByDescending导致超时

时间:2016-08-15 17:12:04

标签: c# entity-framework timeout sql-order-by sql-function

我已经执行了这个表值函数很长一段时间没有问题。看来,我现在无法在没有超时的情况下在EF中成功运行此查询。

#myTable {
  table-layout: fixed;
  width: 100% !important;
}
#myTable td,
#myTable th{
  width: auto !important;
  white-space: normal;
  text-overflow: ellipsis;
  overflow: hidden;
}

我在SQL服务器上运行生成的SQL查询,并以milleseconds返回结果。

context.ItemJobWhereUsed_F(invid, orgid).OrderByDescending(x => x.SCHEDULED_START_DATE).ToList();

我还发现如果我像这样编写lambda它可以正常工作。 (没有超时)

SELECT 
[Project1].[C1] AS [C1], 
[Project1].[DISCRETE_JOB] AS [DISCRETE_JOB], 
[Project1].[CUSTOMER_NAME] AS [CUSTOMER_NAME], 
[Project1].[SCHEDULED_START_DATE] AS [SCHEDULED_START_DATE], 
[Project1].[JOB_STATUS] AS [JOB_STATUS], 
[Project1].[Qty] AS [Qty], 
[Project1].[SCHEDULED_COMPLETION_DATE] AS [SCHEDULED_COMPLETION_DATE], 
[Project1].[LINE] AS [LINE], 
[Project1].[RUN_NUMBER] AS [RUN_NUMBER]
FROM ( SELECT 
    [Extent1].[DISCRETE_JOB] AS [DISCRETE_JOB], 
    [Extent1].[CUSTOMER_NAME] AS [CUSTOMER_NAME], 
    [Extent1].[SCHEDULED_START_DATE] AS [SCHEDULED_START_DATE], 
    [Extent1].[JOB_STATUS] AS [JOB_STATUS], 
    [Extent1].[Qty] AS [Qty], 
    [Extent1].[SCHEDULED_COMPLETION_DATE] AS [SCHEDULED_COMPLETION_DATE], 
    [Extent1].[LINE] AS [LINE], 
    [Extent1].[RUN_NUMBER] AS [RUN_NUMBER], 
    1 AS [C1]
    FROM [eng].[ItemJobWhereUsed_F](@InventoryID, @OrgID) AS [Extent1]
)  AS [Project1]
ORDER BY [Project1].[SCHEDULED_START_DATE] DESC

我很遗憾在哪里可以诊断出这个查询失败的原因。有人能指出我正确的方向来确定这个错误的原因吗?这是运行一个SQL表,其值为EF Model First。

另外值得注意的是,我最近从4.5升级到.NET 4.5.2。

0 个答案:

没有答案