Open Closed

DBContext for tenants #246


User avatar
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)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    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

  • User Avatar
    0
    chanchai-mwp created

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

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

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

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

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

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11