EntityFrameworkCore.Generator icon indicating copy to clipboard operation
EntityFrameworkCore.Generator copied to clipboard

Add support for multiple DbContext-classes

Open HerrLiljegren opened this issue 5 years ago • 4 comments

I'm using efg to generate two different DbContexts, one regular read/write and a second one for read only access.

For this I have two separate .yml-configuration files and I run using efg -f standard-context.yml

The problem is that when I do this, the generator finds the read only DbContext first, and tries to rename it to the standard context name.

I Rename Context Class'PmMarknadSyncDbContext' to 'MarknadReadOnlyDbContext'.

My solution today is to do the generation outside of my project folder and the manually replace the files. But then I loose changes I made outside of #region

HerrLiljegren avatar Jun 18 '19 07:06 HerrLiljegren

I Thing it's always best to have a project for each database, separated from the main application project

capslock66 avatar Jun 18 '19 07:06 capslock66

I Thing it's always best to have a project for each database, separated from the main application project

hmm, I do have a separate project for my database. But I use two different contexts, and one of them is very small (only one table at the moment, might grow a bit in the future). I could separate them in two different projects but I'm feeling it will add unnecessary overhead and complexity.

HerrLiljegren avatar Jun 18 '19 07:06 HerrLiljegren

I'll see if i can come up with a way to specify the DbContext class in the yml file. I've run into the same issue, but slightly different usage.

pwelter34 avatar Jun 18 '19 20:06 pwelter34

Hello Multiple DbContext-classes is also a nice-to-have feature for me. I have a database with 8 schemas. The solution has a separate "*.Data" project with database context for each of them. And I would like to generate a separate database context for each schema. I tried to modify configuration file using "Table.Schema" like this: context: name: '{Table.Schema}Context' baseClass: DbContext propertyNaming: Plural namespace: '{Project.Namespace}.Data' directory: '{Project.Directory}\Data' document: false

Expected to have 8 files, but as a result, only one "Context.cs" file was generated in "Data" directory.

loanst avatar Jan 15 '21 19:01 loanst