"A synchronous store management operation was performed..." when using AddAsyncSeeding with EF Core CLI
When running dotnet ef database update on a project that uses AddAsyncSeeding in OnConfiguring, the following error occurs:
System.InvalidOperationException: A synchronous store management operation was performed and no synchronous seed delegate has been provided, however an asynchronous seed delegate was. Set 'UseSeeding' option with a delegate equivalent to the one supplied in 'UseAsyncSeeding'.
not sure if this is the best solution but replace this code in InitialiserExtensions.cs
public static void AddAsyncSeeding(this DbContextOptionsBuilder builder, IServiceProvider serviceProvider)
{
builder.UseAsyncSeeding(async (context, _, ct) =>
{
var initialiser = serviceProvider.GetRequiredService<ApplicationDbContextInitialiser>();
await initialiser.SeedAsync();
});
builder.UseSeeding((context, _) =>
{
var initialiser = serviceProvider.GetRequiredService<ApplicationDbContextInitialiser>();
// Block on async call for sync context
initialiser.SeedAsync().GetAwaiter().GetResult();
});
}
@Arggon , I solved the problem using the same technique, and it worked successfully.
There is a bug in the template. When implementing Data Seeding (EF Core 9+), it is necessary to implement both UseAsyncSeeding and UseSeeding, the template is only implementing UseAsyncSeeding and is therefore causing the System.InvalidOperationException.
For now, the above solution is a good workaround. I'll release a bugfix soon, however I'll also take a look at the current database initialization and seeding strategy as I feel further improvements can be made.
I've resolved this issue by reverting to the previous, and simpler, initialization and seeding strategy.