2016-12-06 6 views
0

2つのデータベースを持つASP.NET MVCアプリケーションがあります。最初のデータベースは、私は成功しTestModelの移行を可能にし、エラーが発生しIDからのASP.NET MVC移行モデルの検証エラー

add-migration Initial -ConfigurationTypeName project.Migrations.TestMigrations.Configuration 

を実行しようとする標準のIdentityコンテキスト

public class ApplicationUser : IdentityUser { 
    public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager) { 
     // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
     var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie); 
     // Add custom user claims here 
     return userIdentity; 
    } 

    public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager) { 
     return Task.FromResult(GenerateUserIdentity(manager)); 
    } 
} 

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { 
    public ApplicationDbContext() 
     : base("ApplicationConnection", throwIfV1Schema: false) { } 

    public static ApplicationDbContext Create() { 
     return new ApplicationDbContext(); 
    } 
} 

二コンテキスト

public class TestModel : DbContext { 
    public TestModel() 
     : base("Connection") { 
    } 
    public virtual DbSet<A> As { get; set; } 
    public virtual DbSet<B> Bs { get; set; } 
    public virtual DbSet<C> Cs { get; set; } 

}

です

One or more validation errors were detected during model generation: 

project.Models.Tests.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. 

project.Models.Tests.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. 

IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined. 

IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined. 

私はこの問題に関連するものは何も見つかりませんでした。 ありがとうございます。

+0

可能なdup:http://stackoverflow.com/questions/28531201/entitytype-identityuserlogin-has-no-key-defined-define-the-key-for-this-entit –

+0

リンクありがとうございます。 iddueを解決しないでください。私はIdentityが所属するApplicationDbContextでのマイグレーションの実行に問題はありません。この問題は、接続IDがないと想定される第2コンテキストで移行を作成したときに発生し、このモデルでは「Models.Tests.IdentityUserLogin」および「Models.Tests.IdentityUserRole」というクラスは存在しません。どういうわけかEFはApplicationDbContextからそれを取得し、私はそれを修正する方法を見つけることができません。ありがとうございました。 – timk

+0

2番目のコンテキストのモデルはいずれもアイデンティティモデルを参照していますか?また、[各コンテキストの移行を有効にしましたか?](http://stackoverflow.com/questions/21537558/multiple-db-contexts-in-the-same-db-and-application-in-ef-6-and -code-first-migra) –

答えて

0

両方のデータベースのプライマリと外部キーの制約を確認してください。まず、両方のデータベースを個別に接続して、アイデンティティ制約を修復します。移行の場合は、レプリケーションも使用できます。このヒントがあなたを助けてくれることを願っています。