Table of Contents

Class ApplicationBuilderExtensions

Namespace
NuvTools.AspNetCore.EntityFrameworkCore.Extensions
Assembly
NuvTools.AspNetCore.EntityFrameworkCore.dll

Provides extension methods for IApplicationBuilder to support Entity Framework Core operations.

public static class ApplicationBuilderExtensions
Inheritance
ApplicationBuilderExtensions
Inherited Members

Methods

DatabaseMigrate<TContext>(IApplicationBuilder, TimeSpan?)

Applies any pending Entity Framework Core migrations for the specified database context during application startup.

public static IApplicationBuilder DatabaseMigrate<TContext>(this IApplicationBuilder app, TimeSpan? timeout = null) where TContext : DbContext

Parameters

app IApplicationBuilder

The IApplicationBuilder instance.

timeout TimeSpan?

An optional timeout for the migration command. If specified, the command timeout is temporarily set to this value during migration and then restored to its original value.

Returns

IApplicationBuilder

The IApplicationBuilder so that additional calls can be chained.

Type Parameters

TContext

The type of the DbContext to migrate.

Examples

// Apply migrations with default timeout
app.DatabaseMigrate<MyDbContext>();

// Apply migrations with 5-minute timeout
app.DatabaseMigrate<MyDbContext>(TimeSpan.FromMinutes(5));

Remarks

This method creates a temporary service scope to resolve the database context and applies any pending migrations by calling the Database.Migrate() method.

If a timeout is specified, it is applied only during the migration operation and the original timeout is restored afterward.

If the context or database is not available, the method returns without throwing an exception.