EFCore.AutomaticMigrations
8.0.5
dotnet add package EFCore.AutomaticMigrations --version 8.0.5
NuGet\Install-Package EFCore.AutomaticMigrations -Version 8.0.5
<PackageReference Include="EFCore.AutomaticMigrations" Version="8.0.5" />
paket add EFCore.AutomaticMigrations --version 8.0.5
#r "nuget: EFCore.AutomaticMigrations, 8.0.5"
// Install EFCore.AutomaticMigrations as a Cake Addin #addin nuget:?package=EFCore.AutomaticMigrations&version=8.0.5 // Install EFCore.AutomaticMigrations as a Cake Tool #tool nuget:?package=EFCore.AutomaticMigrations&version=8.0.5
About the package
Enable Automatic Migrations for Entity Framework Core for SQL Databases.
Usage
DbMigrationsOptions object allows to configure migration options:
/// <summary>
/// Allow auto migration with data lost.
/// </summary>
public bool AutomaticMigrationDataLossAllowed { get; set; } = false;
/// <summary>
/// Enable to execute auto migration
/// </summary>
public bool AutomaticMigrationsEnabled { get; set; } = true;
/// <summary>
/// Drop all tables from database and recreate based on model snapshot. Useful in scenarios when the data is transient and can be dropped when the schema changes. For example during prototyping, in tests, or for local caches
/// When ResetDatabaseSchema is true AutomaticMigrationsEnabled and AutomaticMigrationDataLossAllowed are set to true
/// </summary>
public bool ResetDatabaseSchema { get; set; } = false;
/// <summary>
/// Allow to update snapshot.The key will pe replaced with value for each KeyValuePair object
/// </summary>
public Dictionary<string, string> UpdateSnapshot { get; set; } = new Dictionary<string, string>();
The package support following ways to apply/view-applied migrations:
- Using MigrateDatabaseToLatestVersion
- Execute<TContext>(TContext context);
- ExecuteAsync<TContext>(TContext context);
- Execute<TContext, TMigrationsOptions>(TContext context, TMigrationsOptions options);
- ExecuteAsync<TContext, TMigrationsOptions>(TContext context, TMigrationsOptions options);
// Get context
var context = services.GetRequiredService<YourContext>();
// Apply migrations
MigrateDatabaseToLatestVersion.Execute(context);
// Reset database schema
MigrateDatabaseToLatestVersion.Execute(context, new DbMigrationsOptions { ResetDatabaseSchema = true });
// Apply migrations async
await MigrateDatabaseToLatestVersion.ExecuteAsync(context);
// Reset database schema async
await MigrateDatabaseToLatestVersion.ExecuteAsync(context, new DbMigrationsOptions { ResetDatabaseSchema = true });
- Using Context extensions methods
- MigrateToLatestVersion<TContext>(this TContext context);
- MigrateToLatestVersionAsync<TContext>(this TContext context);
- MigrateToLatestVersion<TContext, TMigrationsOptions>(this TContext context, TMigrationsOptions options);
- MigrateToLatestVersionAsync<TContext, TMigrationsOptions>(this TContext context, TMigrationsOptions options);
// Get context
var context = services.GetRequiredService<YourContext>();
// Apply migrations
context.MigrateToLatestVersion();
// Reset database schema async
context.MigrateToLatestVersion(new DbMigrationsOptions { ResetDatabaseSchema = true });
// Apply migrations async
context.MigrateToLatestVersionAsync();
// Reset database schema async
await context.MigrateToLatestVersionAsync(new DbMigrationsOptions { ResetDatabaseSchema = true });
- View applied migrations - return list of MigrationOperation object
//Get context
var context = services.GetRequiredService<YourContext>();
// Get applied migrations
List<MigrationRaw> appliedMigrations = context.ListMigrationOperationsAsRawSql();
// Get applied migrations async
List<MigrationRaw> appliedMigrations = await context.ListMigrationOperationsAsRawSqlAsync();
/// <summary>
/// Migration Raw object
/// </summary>
public class MigrationRaw
{
public string MigrationId { get; set; } = string.Empty;
public DateTime? CreatedDate { get; set; } = null;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.5)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.5)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on EFCore.AutomaticMigrations:
Package | Downloads |
---|---|
Dao.LightFramework
Package Description |
|
TCDev.APIGenerator.Data.SQL
Adds necessary functionality to use MS SQL Server and Azure SQL Instances with the API Generator. |
|
TCDev.APIGenerator.Data.SQLite
Adds necessary functionality to use SQLLite with the API Generator. Rasepi greates fully working CRUD Apis from just models |
|
TCDev.APIGenerator.Data.Postgres
Adds necessary functionality to use Postgres databases with the API Generator. Rasepi greates fully working CRUD Apis from just models |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on EFCore.AutomaticMigrations:
Repository | Stars |
---|---|
DeeJayTC/net-dynamic-api
A library that turns your model into a fully working API, define your model as markdown (soon), json or c#.
|
Version | Downloads | Last updated |
---|---|---|
8.0.5 | 9,234 | 5/19/2024 |
8.0.0 | 6,860 | 11/15/2023 |
7.0.11 | 918 | 10/2/2023 |
7.0.10 | 2,320 | 8/20/2023 |
7.0.7 | 1,100 | 6/14/2023 |
7.0.5.2 | 1,844 | 4/28/2023 |
7.0.5.1 | 554 | 4/27/2023 |
7.0.5 | 709 | 4/12/2023 |
7.0.4 | 936 | 3/27/2023 |
7.0.3 | 607 | 3/27/2023 |
7.0.2 | 613 | 3/27/2023 |
7.0.1 | 1,010 | 3/27/2023 |
7.0.0 | 4,137 | 12/4/2022 |
6.0.10.1 | 9,570 | 10/20/2022 |
6.0.10 | 1,303 | 10/12/2022 |
6.0.10-rc | 546 | 10/12/2022 |
6.0.9.1 | 774 | 10/12/2022 |
6.0.8 | 778 | 10/12/2022 |
6.0.7 | 748 | 10/12/2022 |
6.0.6 | 833 | 10/12/2022 |
6.0.5 | 754 | 10/12/2022 |
6.0.4 | 4,957 | 4/15/2022 |
6.0.3.1 | 2,337 | 3/22/2022 |
6.0.3 | 1,634 | 3/22/2022 |
6.0.0.1 | 1,126 | 12/6/2021 |
6.0.0 | 821 | 12/6/2021 |
5.0.0 | 1,880 | 11/26/2020 |
1.0.2 | 1,087 | 11/26/2020 |
1.0.1 | 3,009 | 5/11/2020 |
1.0.0 | 980 | 4/22/2020 |
Update to Microsoft.EntityFrameworkCore version 8.0.5.
Integrated context schemas: Useful for resetting options when the database has multiple schemas.