0
두 개의 별도 데이터베이스가있는 ASP.NET MVC 응용 프로그램이 있습니다. 첫 번째 데이터베이스 표준 신원 컨텍스트Identity에서 ASP.NET MVC 마이그레이션 모델 유효성 검사 오류
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; }
}
I 성공적으로 TestModel에 대한 마이그레이션을 사용하여 오류가 발생
add-migration Initial -ConfigurationTypeName project.Migrations.TestMigrations.Configuration
를 실행하려고
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.
이 문제와 관련된 항목을 찾을 수 없었으므로 도움을 주셔서 감사합니다. 감사합니다.
가능한 회신 : http://stackoverflow.com/questions/28531201/entitytype-identityuserlogin-has-no-key-defined-define-the-key-for-this-entit –
링크 주셔서 감사합니다. iddue를 해결하지 않습니다. Identity가 속한 ApplicationDbContext에서 마이그레이션을 실행하는 데 아무런 문제가 없습니다. 이 문제는 연결 ID가없는 두 번째 컨텍스트에서 마이그레이션을 만들 때 발생하며이 모델에는 "Models.Tests.IdentityUserLogin"및 "Models.Tests.IdentityUserRole"클래스가 없습니다. 어쨌든 EF는 ApplicationDbContext에서 가져오고 그것을 수정하는 방법을 알 수 없습니다. 고맙습니다. – timk
두 번째 컨텍스트의 모델 중 하나라도 ID 모델에 대한 참조가 있습니까? 또한 [각 컨텍스트에 대해 마이그레이션을 활성화 했습니까?] (http://stackoverflow.com/questions/21537558/multiple-db-contexts-in-the-same-db-and-application-in-ef-6-and) -code-first-migra) –