EF6升级后的额外SQL调用

时间:2014-02-22 15:27:36

标签: entity-framework mvc-mini-profiler

我最近在使用miniprofiler时注意到了一些额外的SQL调用。

它们似乎只是在构建之后发生,并且我认为它们在升级到EF6后出现。

他们只是在检查模型的变化吗?

我能安全地忽略它们吗?

SELECT 
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT 
        COUNT(1) AS [A1]
        FROM [dbo].[__MigrationHistory] AS [Extent1]
    )  AS [GroupBy1]



SELECT 
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT 
        COUNT(1) AS [A1]
        FROM [dbo].[__MigrationHistory] AS [Extent1]
        WHERE ([Extent1].[ContextKey] = @p__linq__0) AND (@p__linq__0 IS NOT NULL)
    )  AS [GroupBy1]


SELECT TOP (1) 
    [Project1].[C1] AS [C1], 
    [Project1].[MigrationId] AS [MigrationId], 
    [Project1].[Model] AS [Model]
    FROM ( SELECT 
        [Extent1].[MigrationId] AS [MigrationId], 
        [Extent1].[Model] AS [Model], 
        1 AS [C1]
        FROM [dbo].[__MigrationHistory] AS [Extent1]
        WHERE ([Extent1].[ContextKey] = @p__linq__0) AND (@p__linq__0 IS NOT NULL)
    )  AS [Project1]
    ORDER BY [Project1].[MigrationId] DESC

1 个答案:

答案 0 :(得分:1)

使用Code-First时,这些数据库调用会引用包含Migration HIstory Table的新in EF6功能:

  

迁移历史记录表是Code First Migrations用于存储有关应用于数据库的迁移的详细信息的表。默认情况下,数据库中表的名称为__MigrationHistory,并在应用第一次迁移时创建数据库。在Entity Framework 5中,如果应用程序使用Microsoft Sql Server数据库,则此表是系统表。但是,实体框架6中已更改,并且迁移历史记录表不再标记为系统表。

如果您不使用它们,这些电话不应造成任何伤害。您可以随时为disable themhave EF create DB change scripts代替。