All my searches are coming back to the same one of two issues, which aren't the problem in this project. I've never had trouble with this before, but this particular project is being weird.
First off, the project name is Site
. The class SiteContext
inherits DbContext
.
When I run Enable-Migrations, even explicitly , the Package manager console returns an error:
PM> Enable-Migrations -ContextType SiteContext
The context type 'SiteContext' was not found in the assembly 'Site'.
But it's right there in the code:
// Not in a namespace or anything
public class SiteContext : DbContext {
// public DbSets in here
}
I can use SiteContext
anywhere in my site's code, access the database though an object of it, etc. It's only the Enable-Migrations command that can't find it. Other than this, Entity's code-first functionality is working properly.
Any ideas what might be going on? Where did I mess this up?
(Entity Framework 6.0.2 / Web Pages 3.1.1)
ASP.NET Web Pages sites are built using the Web Site project type. This project type doesn't support Entity Framework Migrations. If you want to use Code First Migrations with an ASP.NET Web Pages site, you need to develop your data access code as a separate class library. That project type does support EF Migrations. I've blogged about it here: http://www.mikesdotnetting.com/Article/217/Code-First-Migrations-With-ASP.NET-Web-Pages-Sites
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With