EFCorePowerTools
EFCorePowerTools copied to clipboard
Using multiple DbContexts in the same project
I have a project that needs to use multiple DbContexts in the same project. I have put the cs files into separate folders, but I prefer to keep the namespaces simpler and have overridden them via the UX.
I now end up with multiple DbContextExtensions.Sync.cs files that cause errors. I have to currently delete one of them or change it's build action to None.
Would it be possible to either have EF Core Power Tools "detect" if one already existed and not create a new one, or, simply add an Advanced option to suppress the DbContextExtensions from being created? Either of these options would make it less confusing to other developers who have to maintain this code after I'm gone.
Provide steps to reproduce
Add multiple DbContexts to a project, but point them to the same namespace (different folders though).
Provide technical details
-
EF Core version in use: EF Core 6
-
Is Handlebars used: no
-
Is .dacpac used: no
-
EF Core Power Tools version: 2.5.1068
-
Database engine: SQL Server
-
Visual Studio version: Visual Studio 2022
But they have namespaces??
You have made them the same??
Correct. They have the same namespaces.
In my scenario, I will never have overlapping model names to deal with, so putting them all into the same namespace is cleaner for me.
Please share a sample project and I will have a think about what can be done.
Sounds a little like an edge case with a lot of anti patterns...
Ping?
You can remove the duplicate file using efpt.postrun.cmd https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#saving-options-and-running-the-second-time
Sorry for the delay in getting back to you with a sample project. I was trying to figure out what two databases you would have access to to try it against.
As for your last comment on using efpt.postrun.cmd, I am perfectly fine with this solution. It suites my needs.
Thank you for your time on this.