There are two online store databases: One main (context inherits from DbContext ), the other contains users ( ApplicationDbContext , inherited from IdentityDbContext<ApplicationUser> ). Both are configured with migrations that I produce separately (according to this guide ).
Today I faced the need to combine them into one database (hosting limits the number of bases), and therefore the question arose: How to move everything, for example, to the main database correctly, without breaking the EF Code First Migrations and Asp.Net Identity "homeostasis"? Will it be possible to combine contexts, given that they are inherited from different classes? What to do next? Or is everything much simpler (for example, 2 contexts in one database)? I ask you step by step to paint, if not actions, then at least the logic of the process that I need to do to solve the problem.
PS: The store is only written, the user is only 1, so the re-creation of the table with users is not scary. If only the output worked.
UPD:
Attaching the main context class at the request of @Bald:
public class ProductContext : DbContext { public DbSet<Product> Products { get; set; } public DbSet<Category> Categories { get; set; } public DbSet<ProductType> ProductTypes { get; set; } public DbSet<TopNote> TopNotes { get; set; } public DbSet<HeartNote> HeartNotes { get; set; } public DbSet<BaseNote> BaseNotes { get; set; } public DbSet<Feature> Features { get; set; } public DbSet<ProductValue> ProductValues { get; set; } public DbSet<Variation> Variations { get; set; } public DbSet<Visitor> Visitors { get; set; } public DbSet<Cart> Carts { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<OrderDetail> OrderDetails { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Product>().HasMany(c => c.ProductTypes) .WithMany(s => s.Products) .Map(t => t.MapLeftKey("ProductId") .MapRightKey("ProductTypeId") .ToTable("Product_ProductTypes")); modelBuilder.Entity<Product>().HasMany(c => c.TopNotes) .WithMany(s => s.Products) .Map(t => t.MapLeftKey("ProductId") .MapRightKey("TopNoteId") .ToTable("Product_TopNotes")); modelBuilder.Entity<Product>().HasMany(c => c.HeartNotes) .WithMany(s => s.Products) .Map(t => t.MapLeftKey("ProductId") .MapRightKey("HeartNoteId") .ToTable("Product_HeartNotes")); modelBuilder.Entity<Product>().HasMany(c => c.BaseNotes) .WithMany(s => s.Products) .Map(t => t.MapLeftKey("ProductId") .MapRightKey("BaseNoteId") .ToTable("Product_BaseNotes")); modelBuilder.Entity<Product>().HasMany(c => c.ProductValues) .WithMany(s => s.Products) .Map(t => t.MapLeftKey("ProductId") .MapRightKey("ProductValueId") .ToTable("Product_ProductValues")); } } and the ApplicationDbContext class, just in case:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("ApplicationDbContext", throwIfV1Schema: false) { } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } }
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>? I did not understand whatpublic DbSet<History> Histories {get;set;}. - Denis Kutovskiyclasswhich you call the main context, i.e. one that inherits fromDbContext- Bald