I am working on an ASP.NET MVC App using code first. When I run the app from inside visual studio (in debug or release mode) my first query is always slower because of the following SQL that runs automatically:
SELECT Count(*)
FROM INFORMATION_SCHEMA.TABLES AS t
WHERE t.TABLE_TYPE = 'BASE TABLE' AND
(t.TABLE_SCHEMA + '.' + t.TABLE_NAME IN
('dbo.LoginAttempt','dbo.Product','dbo.Supplier','dbo.AspNetRoles',
'dbo.AspNetUsers','dbo.AspNetUserClaims','dbo.AspNetUserLogins','dbo.AspNetUserRoles')
OR t.TABLE_NAME = 'EdmMetadata') -- Executing at 2/27/2014 2:43:58 PM -05:00 -- Completed in 20 ms with result: 8
SELECT [GroupBy1].[A1] AS [C1] FROM (
SELECT COUNT(1) AS [A1]
FROM [dbo].[__MigrationHistory] AS [Extent1]
) AS [GroupBy1] -- Executing at 2/27/2014 2:43:59 PM -05:00 -- Completed in 3 ms with result: SqlDataReader
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] -- p__linq__0: 'CompanyName.Migrations.Configuration' (Type = String, Size = 4000) -- Executing at 2/27/2014 2:43:59 PM -05:00 -- Completed in 2 ms with result: SqlDataReader
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 -- p__linq__0: 'CompanyName.Migrations.Configuration' (Type = String, Size = 4000) -- Executing at 2/27/2014 2:43:59 PM -05:00 -- Completed in 2 ms with result: SqlDataReader
I have a few questions regarding this SQL:
- When I release this app to production will this SQL still run with the first query?
- If it does, will this happen for the first query by each user, or just the first query ran on the site?
- Are these queries necessary for EF to work or is there a way to disable them?
Database.SetInitializer<YourContext>(null);