Entity Framework Core is sending this SQL query to the SQL Server:
SELECT
[GroupBy1].[A1] AS [C1]
FROM ( SELECT
COUNT(1) AS [A1]
FROM [dbo].[__MigrationHistory] AS [Extent1]
) AS [GroupBy1]
go
SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[ModelHash] AS [ModelHash]
FROM [dbo].[EdmMetadata] AS [Extent1]
ORDER BY [Extent1].[Id] DESC
go
https://www.tallan.com/blog/2019/05/02/taking-a-look-at-entity-framework-queries-pt-1-net-framework
How can we stop sending these queries?
Application Codes:
This is in Startup.ConfigureServices:
services.AddDbContext<AppContext>(options => options.UseSqlServer(Configuration.GetConnectionString("AppConnectionString")));
And this is DbContext:
public class AppContext: DbContext
{
public AppContext(DbContextOptions<AppContext> options) : base(options)
{
}
public DbSet<Currency> Currency { get; set; }
public DbSet<StateProvince> StateProvinces { get; set; }
}
Problem Statement:
We are not using migration and all tables are already exist. As a result, when Entity Framework Core generates these queries, SQL Server Profiler logs errors because __MigrationHistor and EdmMetadata do not exist.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As @IvanStoev said “EF Core does not automatically issue SQL queries against migration history table”
Those queries were generated by a library that uses Entity Framework 6.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0