Open Closed

DBContext for tenants #246


0
chanchai-mwp created
  • ABP Framework version: v2.9.0
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes

NetZero:

using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) {
using (var dbContext = _dbContextResolver.Resolve<Project1DemoDbContext>(connectionString, null)) { } }

AbpCommercial

How can we get dbcontext for tenants that have different connectionsstrings like NetZero.


4 Answer(s)
  • 0
    liangshiwei created
    Support Team

    Hi,

    Try:

    using (CurrentTenant.Change(Guid.Parse("tenant id")))
    {
        var dbContext= await _repository.GetDbContext();
    }
    

    See https://docs.abp.io/en/abp/latest/Entity-Framework-Core#access-to-the-ef-core-api

  • 0
    chanchai-mwp created

    No luck. Couldn't find .GetDbContext() here.

  • 0
    liangshiwei created
    Support Team

    Hi,

    You need add Volo.Abp.EntityframeworkCore NuGet package to your project.

  • 0
    liangshiwei created
    Support Team

    I close this question, If you still have this question, Please reopen.