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

Ef core migrations has runtime errors, can't use transaction when migrations! #2151

Open
niltor opened this issue Nov 25, 2024 · 4 comments
Open
Labels
⌚ Not Triaged Not triaged

Comments

@niltor
Copy link

niltor commented Nov 25, 2024

Describe the issue or suggestion

In ef-core-migrations.md, there are some codes has runtime error!

After creating a MigrationsService and Worker.cs,just like:

    private static async Task RunMigrationAsync(CommandDbContext dbContext, CancellationToken cancellationToken)
    {
        var strategy = dbContext.Database.CreateExecutionStrategy();
        await strategy.ExecuteAsync(async () =>
        {
            // Run migration in a transaction to avoid partial migration if it fails.
            await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
            await dbContext.Database.MigrateAsync(cancellationToken);
            await transaction.CommitAsync(cancellationToken);
        });
    }

Afte running AspireHost, I got an error: User transaction is not supported with a TransactionSuppressed migrations or a retrying execution strategy.

So why use transaction?

@dotnetrepoman dotnetrepoman bot added the ⌚ Not Triaged Not triaged label Nov 25, 2024
@niltor niltor changed the title Ef core migrations has build error codes, can't use transaction when migrations! Ef core migrations has runtime errors, can't use transaction when migrations! Nov 25, 2024
@denisulmer
Copy link
Contributor

I have the exact same problem.

@bar10dr
Copy link

bar10dr commented Nov 27, 2024

Same here, it seems like .net 9 EF Core is half baked

@davidfowl
Copy link
Member

@AndriySvyryd Do we just need to update our docs and samples?

@AndriySvyryd
Copy link
Member

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

No branches or pull requests

5 participants