Skip to content

fix: handle wildcard '*' in --context parameter for UpdateDatabase an…#38269

Open
BrunoSync wants to merge 2 commits into
dotnet:mainfrom
BrunoSync:fix/wildcard-context-support
Open

fix: handle wildcard '*' in --context parameter for UpdateDatabase an…#38269
BrunoSync wants to merge 2 commits into
dotnet:mainfrom
BrunoSync:fix/wildcard-context-support

Conversation

@BrunoSync
Copy link
Copy Markdown

Fix wildcard '*' support in --context parameter

Fixes #38254

What was done

  • Added wildcard '*' handling in UpdateDatabase — when --context * is passed, the operation now calls CreateAllContexts() and iterates over all found contexts
  • MigrationsBundle is covered by this fix since it internally calls UpdateDatabase
  • Added test UpdateDatabase_with_wildcard_context_runs_for_all_contexts to verify the fix

Pending

AddMigration also needs wildcard support, but since it returns MigrationFiles, iterating over multiple contexts raises a design question about the return value. Looking for guidance on how to handle this before implementing.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds wildcard --context * handling to migration database updates so EF Core tooling can attempt to update all discovered DbContext types.

Changes:

  • Adds a wildcard branch in MigrationsOperations.UpdateDatabase.
  • Adds a test intended to cover wildcard update behavior across multiple contexts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/EFCore.Design/Design/Internal/MigrationsOperations.cs Adds CreateAllContexts() iteration for contextType == "*".
test/EFCore.Design.Tests/Design/Internal/MigrationsOperationsTest.cs Adds wildcard update test coverage.

Comment on lines +223 to +224
var contexts = _contextOperations.CreateAllContexts();
foreach (var item in contexts)
[ConditionalFact]
public void UpdateDatabase_with_wildcard_context_runs_for_all_contexts()
{
var assembly = MockAssembly.Create([typeof(AssemblyTestContext), typeof(TestContext)]);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

using (item)
{
if (connectionString is not null)
item.Database.SetConnectionString(connectionString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet-ef --context * not working

2 participants