Closed Kris-I closed 7 years ago
Hi @Kris-I,
thanks for the compliment :-)
What you are asking is currently not possible out-of the box with the current version of our library.
You could try the following, which is certainly not the best solution but an easy one without rework of the library :
create 1 DbContext per connection string (inheriting from our EntityContextBase) and override the OnConfiguring method to pass in the connection string
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer(your_userbound_connectionstring);
}
register all those contexts in the .NET Core DI container
services.AddSingleton<MyContext, MyContext>();
public IUnitOfWork CreateUnitOfWork<TContext>(bool trackChanges = true, bool enableLogging = false) where TContext : DbContext
{
var context = (TContext)_serviceProvider.GetService(typeof(TContext));
if (!trackChanges)
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var uow = new UnitOfWork(context, _serviceProvider);
return uow;
}
I'm not sure this will work, but it is easy to try out.
I expected only one Context but change the connection string.
Thank for your answer,
Hello,
First, I'd like to thank you for your great job.
In an Web application consuming a webApi, this WebApi use (should) your DAL. When a user try the consume it, they need to login first. I give a sample : companyA\user1 or companyB\user25 the connectionstring name are : companyA or companyB . Depending of this value, the context use a database or another, same schema but another database. Each company has is own database. Is there an easy way to give the connectionstring name for each request ?
Thanks,