Database First - MVC

Asked

Viewed 48 times

3

I have always worked with code first and using only one database. However, I need to work with an application with two databases already created.

To work with two databases, I created this:

Passing by:

inserir a descrição da imagem aqui

Receiving:

inserir a descrição da imagem aqui

Now, how can I work easily to reuse the existing structure of banks, including views ?

  • It depends on what you mean by repurposing. Do the two Databases have objects in common? The two Databases have completely different objects?

  • The two objects have a completely different database. Basically, in one I have a financial accompaniment with duplicates and blablabla already in the other, I have the pre-order that through an ERP, will generate these duplicates. My platform is for transactions, it’s for reports only. I won’t have any delete/edit/add method. So I wanted a simple way to work the consultations in these two banks.

1 answer

2


For read-only contexts, add the following in the context class:

public override int SaveChanges()
{
    throw new AccessViolationException(
         "Contexto é somente leitura.");
}

public override async Task<int> SaveChanges()
{
    throw new AccessViolationException(
         "Contexto é somente leitura.");
}

This ensures that the context cannot make modifications to the database.

Plus, I think you’re already using it accordingly.

Browser other questions tagged

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