How to route different db requests to read only instance

47 views Asked by At

We have our primary database in Europe, and it is replicated using azure to a closer region as a readonly instance. This costs us quite a lot every month and we are only using it to he able to fail over in a disaster situation. We are also limited in sql scaling, as we have to scale both instances, even thoguh the readonly instance sits and does nothing..

However is there not a way we can intelligently use it for read queries? So I want to somehow make a read only db context and it's it's reading, use the close db.

1

There are 1 answers

0
David Browne - Microsoft On

An easy way to do this is to have a MyDbContext and a MyDbContextReadOnly, each configured with an appropriate connection string.

One can be a subclass of the other, or they can both be subclasses of a common custom DbContext.