2 years ago
#74099
user11208424
Use different connection string based on country parameter and do you need to use "using" in EF Core?
Having a few Databases for example:
DB_EN
DB_FR
DB_DE
.
So I created something to get the correct Database by countryCode
:
using (var context = new ApplicationContext(_DbContextConfigurationService.GetConnectionString(countryCode)))
{
return await context
.Set<T>()
.Where(expression)
.FirstOrDefaultAsync();
}
I do this now for every action (CRUD), using the using
statement and creating a new ApplicationContext.
The question is, is there a more proper way to get the correct Database by countryCode
(maybe in the constructor? And is "using"
needed? Because when I see the Microsoft documentation they are not using it.
I also plan to add a UoW layer. Hope it's a bit clear what I mean.
c#
entity-framework-core
dbcontext
0 Answers
Your Answer