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.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 25, 2025, 11:10