EF6 continually Access__MigrationHistory table leading to SQL errors

ps-rizwan 1 Reputation point

Customers have reported slowness in the our application and have seen a large number of errors reported in SQL. The hosted environment’s performance logging tool (NewRelic) has reported an increase in failure rate which the customer suspect is the cause for application slowness. Application uses Entity Framework 6 for data access.

The application uses Entity First Database first approach to access the database. We are seeing the below queries are continuously getting executed on the database:

SELECT Count(*) FROM sys.databases WHERE [name]=N?

SELECT Count(*) FROM INFORMATION_SCHEMA.TABLES AS t WHERE t.TABLE_SCHEMA + ? + t.TABLE_NAME IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) OR t.TABLE_NAME = ?

SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(?) AS [A1] FROM [dbo].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = @p__linq__0 ) AS [GroupBy1]

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

SELECT TOP (?) [Extent1].[Id] AS [Id], [Extent1].[ModelHash] AS [ModelHash] FROM [dbo].[EdmMetadata] AS [Extent1] ORDER BY [Extent1].[Id] DESC

When we checked on the database, we are not able to find the “__MigrationHistory” table neither “EdmMetadata” table.

How should we go about stopping these queries for our application?

Entity Framework 6.0
Entity Framework 6.0
A Microsoft open-source object-database mapper for .NET.
267 questions
Microsoft Technologies based on the .NET software framework.
2,327 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 8,605 Reputation points

    It seems like your application is continuously executing certain queries that are not required and may be causing performance issues. Here are a few steps you can take to stop these queries:

    Check if the Entity Framework context is configured correctly: If the __MigrationHistory and EdmMetadata tables are not present in the database, it is possible that the Entity Framework context is not configured correctly. Check if the database context class is inheriting from the DbContext class and if the migration configuration class is properly set up.

    Disable automatic migrations: If you are not using Entity Framework Migrations, you can disable automatic migrations by setting the "AutomaticMigrationsEnabled" property to "false" in the migration configuration class.

    Optimize your Entity Framework queries: If you are using Entity Framework queries in your application, make sure that they are optimized for performance. You can use the Entity Framework Profiler or SQL Server Profiler to identify any inefficient queries.

    Cache frequently accessed data: If certain data is frequently accessed, consider caching it in memory to reduce the number of database queries.

    Tune your database: If your database is experiencing performance issues, consider tuning it by optimizing indexes, updating statistics, and monitoring database performance metrics.

    Use a performance monitoring tool: Use a performance monitoring tool like SQL Server Profiler or New Relic to identify the root cause of the performance issues and to monitor the impact of any changes made to the application or database.

    By taking these steps, you should be able to identify and stop the unnecessary queries that are causing performance issues in your application.

    0 comments No comments