Question

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)

Was it helpful?

Solution

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

OTHER TIPS

Instead of -ContextType, use -ProjectName and Specify Site.

Edit: First, try -ContextTypeName. I have to assume you didn't.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top