我有两个独立数据库的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; }
}
我成功启用了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.
我无法找到与此问题相关的任何内容,并感谢此处的任何帮助。 谢谢。
答案 0 :(得分:0)
请检查两个数据库中的主要和外国人密钥约束。首先通过单独连接两个数据库来修复身份约束对于迁移,您也可以使用复制。希望这个暗示能帮到你。