BEST
DEALS
OF THE
YEAR!
SAVE UP TO $3,000
24 NOV
1 DEC
00 Days
00 Hrs
00 Min
00 Sec
Open Closed

Cast DBContext to a specific DBContext #534


User avatar
0
joe@tronactive.com created
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes

I need to use the GetDbContext from a repository just like in these documents https://docs.abp.io/en/abp/1.0/Entity-Framework-Core it states about 3/4 down on the page "GetDbContext returns a DbContext reference instead of BookStoreDbContext. You can cast it, however in most cases you don't need it."

I need to do this since my project has several DbContexts but I haven't found a good way to cast it yet. Do you have any examples or suggestion?


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    I think you just need to var bookStoreDbContext = (BookStoreDbContext)repository.GetDbContext();

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on November 20, 2025, 09:12
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.