I am using EntityFramework 5.0 and I have a database that already exists but I want to define my own model for it so I do something like this:
pubilc class MyContext : DbContext
{
public MyContext()
{
Whatevers = Set<Whatever>();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//.. Deal with all the mappings between the real database and
// my beautiful model
}
pubilc DbSet<Whatever> Whatevers { get; private set;}
}
public class Whatever
{
//... you get the gist...
}
It works fine except for the fact that the first time I start up the application it attempts to execute these two 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
Now, neither of those tables exist and therefore I get errors, and I really don't want them to (this is a database that has been around for a while and I am just a lowly application developer not a database overlord).
I saw this question: How to disable migration in Entity Framework 4.3.1? that suggested this:
Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists());
But according to MSDN that is the default, in version 5.0 at least, anyway.
I see in MSDN that there are also:
- DropCreateDatabaseAlways
- DropCreateDatabaseIfModelChanges
- MigrateDatabaseToLatestVersion
But none of those sound like what I want.
Is there a "leave the database alone - it doesn't know about the entity framework and, quite honestly, doesn't care to know about it" IDatabaseInitializer implementation somewhere?
Is it possible to make one?
Or is there some other property I can tweak - I could not find the AutomaticMigrationsEnabled
property mentioned in the answers to the question anywhere.
Or, perhaps there is a crucial reason why I actually need to have those tables in the database?