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

后端 未结 24 2103
野的像风
野的像风 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:31

    I created a Class in the Models directory called: myData with the following code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.Entity;
    
    namespace Vidly.Models
    {
        public class MyDbContext : DbContext
        {
            public MyDbContext()
            {
            }
        }
    }
    

    rebuilt the app with: control-shift-b

    then ran the following in the nuGet Console:

    Enable-Migrations -StartUpProjectName Vidly -ContextTypeName Vidly.Models.MyDbContext -Verbose

    the Console returned:

    Using StartUp project 'Vidly'. Using NuGet project 'Vidly'. Checking if the context targets an existing database... Code First Migrations enabled for project Vidly. Enable-Migrations -StartUpProjectName Vidly -ContextTypeName Vidly.Models.myData -Verbose

    And the FrameWork created a Migrations directory and wrote a Configuration.cs template in there with the following code:

    namespace Vidly.Migrations
    {
        using System;
        using System.Data.Entity;
        using System.Data.Entity.Migrations;
        using System.Linq;
    
        internal sealed class Configuration : DbMigrationsConfiguration
        {
            public Configuration()
            {
                AutomaticMigrationsEnabled = false;
            }
    
            protected override void Seed(Vidly.Models.MyDbContext context)
            {
                //  This method will be called after migrating to the latest version.
    
                //  You can use the DbSet.AddOrUpdate() helper extension method 
                //  to avoid creating duplicate seed data.
            }
        }
    }
    

提交回复
热议问题