I am using Entity Framework 5 and doing a simple query to get a few users from a table.
The SQL database is already created so I use my entities as a way to map what
Since the database is already there you will not have dbo.EdmMetadata
and dbo.__MigrationHistory
which codefirst is expecting. And to resolve this you can try to set the SetInitializer
to null.
static NameOfYourContext()
{
Database.SetInitializer<NameOfYourContext>(null);
}
You can see this in the comments section of the this post by Scott Gu
There are 3 steps you need to follow:
1- Enable migrations in package manager if you haven't done yet:
Enable-Migrations
2- Add a migration and make sure to use the -IgnoreChanges switch as you already have an existing database:
Add-Migration InitialModel -IgnoreChanges
3- Update the database. This will automatically create __MigrationHistory table for you.
Update-Database
I disabled my exception setting. and it overlooked this exception and went on to create these tables for me automatically