EF& MVC:相同的数据库,不同的查询

时间:2014-06-05 17:31:46

标签: asp.net-mvc entity-framework entity-framework-4

我有一个奇怪的情况,我有一个开发。和MVC应用程序的登台服务器。我对dev进行了一些更新,一切都很好,当我将它发布到登台服务器时,使用EF与数据库通信时出现了一些奇怪的错误。

我已经跟踪了这个问题,即EF调用根据服务器生成不同的SQL。我已经确认代码是相同的,并且数据库连接也是一样的,那么为什么查询中存在差异?

两台服务器上唯一不同的是web.config文件。 web.config不会在发布时发送。这让我觉得有一些配置的东西是导致所有这些麻烦的原因。我所能看到的与EF相关的两个文件都是一样的,所以我不太确定。

可能是造成差异的原因是什么?

以下是dev的工作版本:

exec sp_executesql N'SELECT 
[Extent1].[theID] AS [theID], 
[Extent1].[otherID] AS [otherID], 
[Extent1].[field1] AS [field1], 
[Extent1].[field2] AS [field2], 
[Extent1].[field3] AS [field3], 
[Extent1].[field4] AS [field4], 
[Extent1].[field5] AS [field5], 
[Extent1].[field6] AS [field6], 
[Extent1].[field7] AS [field7], 
[Extent2].[field8] AS [field8], 
[Extent2].[field9] AS [field9], 
[Extent2].[field10] AS [field10]
FROM   [dbo].[table1] AS [Extent1]
LEFT OUTER JOIN (SELECT 
      [view1].[field8] AS [field8], 
      [view1].[field9] AS [field9], 
      [view1].[field10] AS [field10]
      FROM [dbo].[view1] AS [view1]) AS [Extent2] ON ([Extent2].[field8] = [Extent1].[field8]) AND ([Extent1].[field8] IS NOT NULL)
LEFT OUTER JOIN (SELECT 
      [view1].[field8] AS [field8], 
      [view1].[field9] AS [field9], 
      [view1].[field10] AS [field10]
      FROM [dbo].[view1] AS [view1]) AS [Extent3] ON ([Extent3].[field8] = [Extent1].[field8]) AND ([Extent1].[field8] IS NOT NULL)
WHERE ([Extent1].[theID] = @p__linq__0) AND ([Extent1].[field3] = @p__linq__1)',N'@p__linq__0 int,@p__linq__1 varchar(8000)',@p__linq__0=1,@p__linq__1='searchVal'

以及来自登台服务器的损坏的非工作状态。

exec sp_executesql N'SELECT 
[Extent1].[theID] AS [STORE_ID], 
[Extent1].[otherID] AS [otherID], 
[Extent1].[field1] AS [field1], 
[Extent1].[field2] AS [field2], 
[Extent1].[field3] AS [field3], 
[Extent1].[field4] AS [field4], 
[Extent1].[field5] AS [field5], 
[Extent1].[field6] AS [field6], 
[Extent1].[field7] AS [field7], 
[Join1].[field81] AS [field8], 
[Join1].[field9] AS [field9], 
[Join1].[field10] AS [field10], 
[Join3].[otherID] AS [otherID1]
FROM   [dbo].[table1] AS [Extent1]
LEFT OUTER JOIN  (SELECT [Extent2].[field8] AS [field81], [Extent2].[field9] AS [field9], [Extent2].[field10] AS [field10]
    FROM  (SELECT 
      [view1].[field8] AS [field8], 
      [view1].[field9] AS [field9], 
      [view1].[field10] AS [field10]
      FROM [dbo].[view1] AS [view1]) AS [Extent2]
    LEFT OUTER JOIN [dbo].[table1] AS [Extent3] ON ([Extent3].[field8] IS NOT NULL) AND ([Extent2].[field8] = [Extent3].[field8]) ) AS [Join1] ON [Extent1].[field8] = [Join1].[field81]
LEFT OUTER JOIN  (SELECT [Extent4].[field8] AS [field82], [Extent5].[otherID] AS [otherID]
    FROM  (SELECT 
      [view1].[field8] AS [field8], 
      [view1].[field9] AS [field9], 
      [view1].[field10] AS [field10]
      FROM [dbo].[view1] AS [view1]) AS [Extent4]
    LEFT OUTER JOIN [dbo].[table1] AS [Extent5] ON ([Extent5].[field8] IS NOT NULL) AND ([Extent4].[field8] = [Extent5].[field8]) ) AS [Join3] ON [Extent1].[field8] = [Join3].[field82]
WHERE ([Extent1].[STORE_ID] = @p__linq__0) AND ([Extent1].[field3] = @p__linq__1)',N'@p__linq__0 int,@p__linq__1 varchar(8000)',@p__linq__0=1,@p__linq__1='searchVal'

正如你所看到的,有一堆额外的连接等,所以到底发生了什么?

0 个答案:

没有答案