Multiple Contexts Migrations Entity Framework

Asked

Viewed 957 times

15

I have several projects and each project has a context.
I would like to know, how to use the Migrations to update and generate only one database of these various contexts?

  • 1

    have you read this article: https://msdn.microsoft.com/en-us/data/jj591621.aspx. ? In this article he mentions a new EF6 configuration that allows this, ContextKey,

  • Yes, but it does not specify about the various projects and contexts.

  • And the entities of the Projects communicate with each other

  • 1

    See if this thred helps you, http://stackoverflow.com/a/10009491/2187618.

  • a while ago already... managed to solve? I understood that each project has a context, but the structure of the bank is the same used by all of them?

  • As far as I know to generate a single bank all contexts must point to the same path to be able to unify all entities

Show 1 more comment

4 answers

1

Multiple contexts are useful for structuring/isolating project areas; obviously this increases complexity. Then you can create each context by pointing to the same basis and perform the work normally.

-1

-2

You create only ONE connection, and use it for your project. So:

Context contexto = new Context();   <----(cria uma conexao)

ProjetoRepository nomeRepositorio = new ProjetoRepository (contexto);
(ProjetoRepository usando a conexao "contexto ")

OutroProjetoRepository nomeOutroReposito = new OutroProjetoRepository (contexto);
(OutroProjetoRepository usando a mesma conexao "contexto ")

-4

Since each context is a completely different instance I believe that this is not possible. Unless you create a context that manages all contexts and encompasses in one.

  • 7

    If you don’t think it’s possible, demonstrate why. If you think it’s creating a context that manages others, demonstrate what to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.