質問

サンプルMVC5プロジェクトに基づく私は移行を処理するための適切な方法を学びようとしています。

ルートディレクトリには、2つのコンテキストを持つ "dbcontexts"というフォルダがあります。

最初のもの:IdentityContext.cs

    public class IdentityContext : IdentityDbContext<ApplicationUser>
{
    public IdentityContext()
        : base("DefaultConnection")
    { }
}
.

その後Configuration.cs

でIdentitySigrationsというフォルダがあります。
    internal sealed class Configuration : DbMigrationsConfiguration<TryFive.Web.DbContexts.IdentityContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
        MigrationsDirectory = @"DbContexts\IdentityMigrations";
    }

    protected override void Seed(TryFive.Web.DbContexts.IdentityContext 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" }
        //    );
        //
    }
}
.

それから私は同様のプロパティを持つMyContextを持っています。

"update-database"コマンドを実行しようとすると、このエラーメッセージ:The type 'TryFive.Web.DbContexts.IdentityContext' does not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.

このDBContextのものを修正する方法についての考えは?

役に立ちましたか?

解決

提案:あなたが言うようにマイグレーションを学ぶためにサンプルプロジェクトをしているだけである場合は、1つのDBContextに固執してください。Simpleに保存 - entiveを1つのDBContextにマージするIdentityDbContext<ApplicationUser>

から継承する1つのDBContextにマージします。

既存のマイグレーションフォルダを削除した - 2番目のDBContextを削除した後に「enable-migrations」を削除します。これは、1つのプロジェクトで2つのDBContextを使用する方法を学習するのではなく、マイグレーションを継続するのに役立ちます。

また、@Lajos、私はどのMVCについて話しているのかわかりませんが、DBContextはDBMigrationsConfigurationから継承されていません - DBContext、またはIdentityDBContextから継承していません。あなたが参照しているものは、プロジェクトで "enable-migrations"を発行するときに生成されるMigrationsConfigurationクラスです。それは移行と播種データの生成に使用されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top