I have a context class that inherits from an abstract base AuditableDbContext : DbContext
. The AuditableDbContext
takes two parameters, one for the auditor and one for the context to audit into.
In the inherited class, I have a default parameterless constructor that calls the other constructors with null parameters and then in the final constructor I call Database.SetInitializer<MyDbContext>(null)
after calling the base constructor.
The problem is that even when I do this, I still get the db migration calls on the database server when the application starts.
public abstract class AuditableContext : DbContext
{
public AuditableContext(IAuditor auditor, DbContext auditContext)
{
// params can be null resulting in no auditing
// initialization stuff here...
}
}
public class MyDbContext : AuditableContext
{
// DbSets here...
public MyDbContext() : this(null, null) {}
public MyDbContext(IAuditor auditor) : this(auditor, null) {}
public MyDbContext(IAuditor auditor, DbContext auditContext)
: base(auditor, auditContext)
{
Database.SetInitializer<MyDbContext>(null);
}
}
The queries I see on the database are the two common migration queries...
SELECT [GroupBy1].[A1] AS [C1]
FROM ( SELECT COUNT(1) AS [A1]
FROM [dbo].[__MigrationHistory] AS [Extent1]
) AS [GroupBy1]
SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[ModelHash] AS [ModelHash]
FROM [dbo].[EdmMetadata] AS [Extent1]
ORDER BY [Extent1].[Id] DESC
Any ideas on how to stop Entity Framework from making these queries?