EF 5 Enable-Migrations : No context type was found in the assembly

后端 未结 24 2087
野的像风
野的像风 2020-12-02 11:51

I have 4 projects :

Toombu.Entities : all models are there
Toombu.DataAccess: Mapping, Repository and ToombuContext
Toombu.Logique : Logic of my application         


        
24条回答
  •  悲哀的现实
    2020-12-02 12:32

    Follow the below steps to resolve the issue

    Install-Package EntityFramework-IncludePrerelease
    

    or Install entity framework from Nuget Package Manager

    Restart visual studio

    After that I was getting "No context type was found in assembly"

    To resolve it - This "No context" that mean you need to create class in "Model" folder in your app with suffix like DbContext ... like this AppDbContext. 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 run the below command on Package Manager:

    Enable-Migrations -ProjectName  -ContextTypeName 
    

    My Project Name is - MyFirstApp and AppDbContext is inside the Model Folder so path is like

    Enable-Migrations -StartUpProjectName MyFirstApp -ContextTypeName MyFirstApp.Models.AppDbContext
    

提交回复
热议问题