How to stop migration in Entity Framework 6 once and for all?

c# ef-database-first ef-migrations entity-framework entity-framework-6

Question

I am using Entity Framework 6 with an ASP.NET MVC 5 application. I do NOT want to use code-first approach in my project.

I created a new project and never enabled migrations. I created a new class called MyContext which extends DbContext class. Here is what I have in MyContext constructor

public MyContext()
    : base(ConnectionName)
{
        Database.SetInitializer<MyContext>(null);
}

However, each time I debut the application, I see the following output in my Debug output screen.

SELECT Count(*)
FROM INFORMATION_SCHEMA.TABLES AS t...

and

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

How can I really stop migration in my application?

1
1
3/20/2017 7:27:32 PM

Popular Answer

If it is true you have not Migrations folder, and no Configuration.cs file, the only thing I think you missed is the database initializer. Even if you are disabling database initialization with Database.SetInitializer<MyContext>(null);, it can be configured using the configuration file:

To disable it using configuration files, add (source):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>    
        <add key="DatabaseInitializerForType MyNamespace.MyDbContext, MyNamespace" 
             value="Disabled" />
    </appSettings>
</configuration>
3
3/20/2017 4:56:59 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow