Does the EntityFramework Core driver for MongoDB support database seeding via UseSeeding()?

I am trying to learn too many things at once :slight_smile: C#, entity framework, and Mongo. I’m running into an issue where the database seeding logic I’m putting into my UseSeeding() is not running.

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        databaseSettings.AddToDbContext(optionsBuilder, "MyDatabase");
        optionsBuilder.UseSeeding(
            (context, _) =>
            {
                context.Set<Data>().Add(...);
                context.SaveChanges();
            }
        ).UseAsyncSeeding(
            async (context, _, cancellationToken) =>
            {
                context.Set<User>().Add(defaultAdminUser);
                await context.SaveChangesAsync(cancellationToken);
            }
        );
    }

Is UseSeeding supported for the MongoDB entity framework driver?

The EF provider does not support seeding or any of the database migration tooling from EF as that is, unfortunately, highly relational based.

Thanks. Is there a best practice for ensuring the database has its required initial data while using the MongoDB EF provider?

You would need to write some logic at app start-up that detected if the data expected was present and if not insert it.