在程序集中找不到迁移配置类型

时间:2018-07-13 09:30:29

标签: entity-framework

我有不同的DbContext连接到不同的数据库。添加迁移时,我的前两个DbContext工作正常,但添加的最后一个DbContext(FinalPmisDbContext)无法添加迁移。我已经在PM中尝试了这两个命令

Enable-Migrations -ContextTypeName SosaPmisApi.Models.FinalPmisDbContext -Force

这是我得到的结果:

Checking if the context targets an existing database...
Code First Migrations enabled for project SosaPmisApi.

然后我运行以下命令:

add-migration -ConfigurationTypeName SosaPmisApi.Migrations.FinalPmisDbContext.Configuration "AddedPropertySoa"

但是我得到这个错误: 迁移配置类型'SosaPmisApi.Migrations.FinalPmisDbContext.Configuration' was not be found in the assembly 'SosaPmisApi'.

这是我的DbContext:

using SosaPmisApi.Models.FinalCurtain;
using System.Data.Entity;

namespace SosaPmisApi.Models
{
    public class FinalPmisDbContext : DbContext
    {
        public FinalPmisDbContext() : base("RevisionConnection") { }

        public DbSet<PropertySoaDates> PropertySoaDates { get; set; }
    }
}

编辑 我可以看到具有此功能的Configuration.cs。

namespace SosaPmisApi.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<SosaPmisApi.Models.FinalPmisDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(SosaPmisApi.Models.FinalPmisDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}

0 个答案:

没有答案