Answer the question
In order to leave comments, you need to log in
How to move tables to another db using EF Code First?
There are two online store databases: One is the main database (the context is inherited from DbContext
), the other contains users ( ApplicationDbContext
, is inherited from IdentityDbContext<ApplicationUser>
). On both, migrations are configured, which I perform separately (according to this guide).
Today I faced the need to combine them into one database (hosting limits the number of databases), and therefore the question arose: How to move everything, for example, to the main database correctly without violating the "homeostasis" of EF Code First Migrations and Asp.Net Identity? Is it 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 to describe step by step, if not actions, then at least the logic of the process that I need to do to solve the problem.
PS: Of course, the “handles” option is also suitable, after which Code First will not complain.
PPS: The store is only being written, there is only 1 user, so re-creating a table with users is not scary. If only everything worked out.
Answer the question
In order to leave comments, you need to log in
Several contexts in one database coexist remarkably well, you only need to specify your own key for each
internal sealed class Configuration : DbMigrationsConfiguration<Models.ApplicationDbContext>
{
public Configuration()
{
...
ContextKey = "ApplicationDbContextKeyName";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question