Open Closed

ABP Suite: Unable to Target Custom DbContext When Creating New Entity in Multi-DbContext Solution #9528


User avatar
0
ihugo created

Hi ABP Team,

I'm working on a solution that uses multiple DbContexts to isolate certain functional domains into separate databases. For example:

  • ReferenceDataDbContext (e.g., for lookup/reference data)
  • MainAppDbContext (standard ABP modules and business logic)

This setup allows us to decouple cross-cutting concerns, so other solutions can integrate with ReferenceData without needing to access or be aware of core ABP tables like identity, audit logs, etc. It also simplifies permissions, as we don’t want to manage fine-grained access to specific tables—we prefer to isolate at the database level.

Following the ABP documentation, I’ve:

  • Created the new ReferenceDataDbContext and its factory
  • Registered it in the migrator project
  • Integrated it with the test project
  • Successfully created and applied migrations

The ReferenceData database is created and operational.

However, when I open ABP Suite to create a new entity, **there is no option to select which DbContext **the entity should be added to. It appears to default to the main AppDbContext, which is not what I want in this case.

My goal: I’d like to generate new entities using ABP Suite and have them scaffolded against the appropriate DbContext (e.g., ReferenceDataDbContext) instead of always defaulting to the main one.

Questions:

  1. Is there a supported way to register additional DbContexts with ABP Suite so they show up as a selectable target when generating new entities?
  2. If not currently supported, is this planned for a future release?
  3. Are there recommended workarounds (e.g. manual adjustments to generated code) to make this smoother?

Thanks in advance for your guidance!


1 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. As of ABP v9.2.1, ABP Suite does not provide a built-in UI option to select or target a custom DbContext when generating new entities. By default, Suite scaffolds entities into the main application DbContext.

    2. There is no official documentation or roadmap entry confirming that multi-DbContext selection in ABP Suite is planned for a future release.

    3. Recommended Workaround:

      • Use ABP Suite to generate the entity as usual (it will target the main DbContext).
      • Manually move the generated entity, configuration, and repository code to your desired DbContext (e.g., ReferenceDataDbContext).
      • Update the DbContext and module registration accordingly.
      • Adjust the migration and dependency injection setup to ensure your new entity is managed by the correct context.

    This approach aligns with current ABP practices for multi-DbContext solutions. For more details and examples on handling multiple DbContexts and related repository patterns, see the following validated resources:

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

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.0.0-preview. Updated on July 09, 2025, 06:20