EF 5 Enable-Migrations : No context type was found

2019-01-10 14:33发布

I have 4 projects :

Toombu.Entities : all models are there
Toombu.DataAccess: Mapping, Repository and ToombuContext
Toombu.Logique : Logic of my application
Toombu.Web : MVC 4 application. With all others DLL.

I tried to enable migration in Toombu.Web but i had this error :

No context type was found in the assembly

How can I enable migration ?

16条回答
Bombasti
2楼-- · 2019-01-10 15:01

Adding a class which inherits DbContext resolved my problem:

public class MyDbContext : DbContext { public MyDbContext() { } }
查看更多
Emotional °昔
3楼-- · 2019-01-10 15:04

Change the default project and choose the startup project from dropdown: enter image description here

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-10 15:06

My problem was link----> problem1

I solved that problem with one simple command line

Install-Package EntityFramework-IncludePrerelease

After that, i needed to face with one more problem, something like:

"No context type was found in assembly"

I solve this really easy. This "No context" that mean you need to create class in "Model" folder in your app with suffix like DbContext ... like this MyDbContext. There you need to include some library using System.Data.Entity;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;


namespace Oceans.Models
{
    public class MyDbContext:DbContext
    {
        public MyDbContext()
        {
        }
    }
}

After that,i just needed this command line:

Enable-Migrations -ProjectName <YourProjectName> -ContextTypeName <YourContextName>
查看更多
Luminary・发光体
5楼-- · 2019-01-10 15:07
namespace EntityFrameworkCodeFirst.Module
{
    public class MyDbContext: DbContext
    {
        public MyDbContext()
        {
        }
    }
}

And if you have Multiple project in one solution than you have to use below commands:-

Enable-Migrations -ProjectName EntityFrameworkCodeFirst
查看更多
登录 后发表回答