DbContextScope icon indicating copy to clipboard operation
DbContextScope copied to clipboard

Same schema for many databases

Open mrbillo opened this issue 9 years ago • 3 comments

We have many databases all exactly the same. We may open more than one context that are the same type. We use a generated connection string to accomplish this. Will this system know the difference between contexts when the type is the same but the connection is different ? Thanks

mrbillo avatar Dec 17 '15 15:12 mrbillo

The solution does allow you to specify your own connection string/connection name. With that facility you can write your own Connection String Generator class that will be able to take a standard connection string (from web.config) and replace the appropriate SQL Server Instance/Database Name on the fly. Worked for me.

BloodBaz avatar Dec 17 '15 15:12 BloodBaz

I don't want to reuse the same context and change the database. I understand how to manage the connection string. The issue is: create context to database A create a context to database B. DbContextScope seems to match on context type which would be the same so it would return the context for database A instead of a new one. I would want to treat these separate so two context are created, each pointing to the correct database.

mrbillo avatar Dec 17 '15 15:12 mrbillo

I see this is an old question, but for what it's worth: If you typically need simultaneous access to 2 of these databases (rather than a large number of parallel simultaneous connections) then you could consider to make 2 subclasses of your DbContext: DbContextA and DbContextB. It gives you 2 separate types.

joepwijers avatar Mar 05 '19 09:03 joepwijers