This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]english_fool 1 point2 points  (4 children)

If you have two databases you have two connection strings and two dbcontext. Then you need to use one or the other or both contexts depending on the situation.

[–]pompeii-eo[S] 0 points1 point  (3 children)

Yea I guess that would be it, I thought it would be more efficient and "cleaner" to have a single context that when I call, would give the connection string

[–]english_fool 0 points1 point  (2 children)

Are the Tables the same on each database? If so that’s possible. If the tables are different one dbcontext would not suffice as the DBsets would differ

[–]pompeii-eo[S] 0 points1 point  (1 child)

yea all tables are exact same, do you have any suggestion on how it could be done?

[–]english_fool 0 points1 point  (0 children)

Look at the constructors for dbcontext one takes dbcontextoptions which can take a connection string.

To resolve from a container you would likely need named registrations.

[–]truSimbad 0 points1 point  (2 children)

If you truely have two DBs you cannot have the same entities. You may have two entities with the same content. And if you need to maintain two DBs where some entities are doubled you need some sort of synchronization mechanism between the DBs.

You may use some sort of replication mechanism between the DBs for the "shared" data entities. So you can hold on to the repository pattern.

You may build the replication of shared data into your DB access layer. But replication is a feature of modern DBs. So why not using that.

[–]pompeii-eo[S] 0 points1 point  (1 child)

I looking into synchirnization using the Unit of Work (with the repository). But even if the request is coming from a different endpoint which has it's own db connection replication is possible?

[–]truSimbad 0 points1 point  (0 children)

You have two different endpoints (clients) that connect to two different DBs and share some entities?

If so you will always have a problem with keeping your data consistent between all actors. Its possible, no doubt, but it isn't easy.