Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple DbContext-classes #23

Open
HerrLiljegren opened this issue Jun 18, 2019 · 4 comments
Open

Add support for multiple DbContext-classes #23

HerrLiljegren opened this issue Jun 18, 2019 · 4 comments

Comments

@HerrLiljegren
Copy link

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

@capslock66
Copy link

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

@HerrLiljegren
Copy link
Author

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.

@pwelter34
Copy link
Member

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.

@loanst
Copy link

loanst commented Jan 15, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants