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

Feature request: Migrations on Inherited DbContexes #5572

Closed
hikalkan opened this issue May 28, 2016 · 5 comments
Closed

Feature request: Migrations on Inherited DbContexes #5572

hikalkan opened this issue May 28, 2016 · 5 comments

Comments

@hikalkan
Copy link

Hi,

Situation

Assume that we have created a modular application and we have more than one DbContext.

Example: In our core part of the application, we have a CommonDbContext:

public class CommonDbContext : DbContext
{
    //common entity DbSet properties
}

And we have several modules (in their own assemblies), like:

public class BlogModuleDbContext : CommonDbContext
{
    //Blog module's additional entity DbSet properties
}

public class ChatModuleDbContext : CommonDbContext
{
    //Chat module's additional entity DbSet properties
}

In this case, I want to have 3 separated migrations normally:

  1. Migration for CommonDbContext .
  2. Migrations for BlogModuleDbContext (which should not include CommonDbContext entities).
  3. Migrations for ChatModuleDbContext (which should not include CommonDbContext entities).

At this point, as you know, derived DbContext's automatic migration generation code include base DbContext (CommonDbContext) changes. While this can be desired in some situations, as you see it's not good for my application.

Feature Request

Define an attribute (and a method in fluent configuration) to ignore base changes:

[IgnoreBaseDbContextMigrations]
public class BlogModuleDbContext : CommonDbContext
{
    //Blog module's additional entity DbSet properties
}

Entity Framework migration generator should understand IgnoreBaseDbContextMigrations attribute and should not detect base class changes.

IgnoreBaseDbContextMigrations can be enhanced. For example, we may supply a DbContext class type to indicate which will be ignored, and so on... Also, there can be technical problems on some situations (for example, on entity inheritance) which should be thought carefully.

What do you think for such a feature, or do you know any other approach to implement the same requirement?

@rowanmiller
Copy link
Contributor

This is already covered by an existing item on our backlog #2725. I've added a note to that issue to specifically consider the inherited context scenario when looking at it.

@hikalkan
Copy link
Author

hikalkan commented Jun 6, 2016

Thank you. I have not seen it. Is there a workaround currently?

@bricelam
Copy link
Contributor

bricelam commented Jun 6, 2016

The workaround is to just remove any operations on them that get scaffolded in the migration.

@hikalkan
Copy link
Author

hikalkan commented Jun 7, 2016

I'm already doing it, I could not find a better way yet. Thanks.

@armartinez
Copy link

Question, how are you handling injection of DbContextOptions ? Or you are not injecting them?

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

5 participants