EFCore.AutomaticMigrations.NetTopologySuite 7.0.5

dotnet add package EFCore.AutomaticMigrations.NetTopologySuite --version 7.0.5                
NuGet\Install-Package EFCore.AutomaticMigrations.NetTopologySuite -Version 7.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EFCore.AutomaticMigrations.NetTopologySuite" Version="7.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EFCore.AutomaticMigrations.NetTopologySuite --version 7.0.5                
#r "nuget: EFCore.AutomaticMigrations.NetTopologySuite, 7.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EFCore.AutomaticMigrations.NetTopologySuite as a Cake Addin
#addin nuget:?package=EFCore.AutomaticMigrations.NetTopologySuite&version=7.0.5

// Install EFCore.AutomaticMigrations.NetTopologySuite as a Cake Tool
#tool nuget:?package=EFCore.AutomaticMigrations.NetTopologySuite&version=7.0.5                

About the package

Enable Automatic Migrations for Entity Framework Core NetTopologySuite for SQL Databases.

Usage

Enable mapping to spatial types via NTS

options.UseSqlServer( @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Database", x => x.UseNetTopologySuite());

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;

The package support following ways to apply/view-applied migrations:

  1. 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 });
  1. 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 });
  1. View applied migrations - return list of MigrationOperation object
  //Get context
  var context = services.GetRequiredService<YourContext>();
  // Get applied migrations
   List<MigrationRaw> appliedMigrations = context.ListMigrations();
  // Get applied migrations async
   List<MigrationRaw> appliedMigrations = await context.ListMigrationsAsync();
  
   /// <summary>
   /// Migration Raw object
   /// </summary>
   public class MigrationRaw
   {
       public string MigrationId { get; set; } = string.Empty;
       public DateTime? CreatedDate { get; set; } = null;
   }
  1. View migration operations which will be applied as raw sql [added in 7.0.5]
 //Get context
 var context = services.GetRequiredService<YourContext>();
 // List migration operations which will be applied as raw sql
  var migrationOperationsAsRawSql = context.ListMigrationOperationsAsRawSql();
 // ist migration operations which will be applied as raw sql async
  var migrationOperationsAsRawSql = await context.ListMigrationOperationsAsRawSqlAsync();

Release 7.0.5

Breaking Changes

ListMigrations and ListMigrationsAsync methods are marked as deprecated and will be removed in further. Please use ListAppliedMigrations / ListAppliedMigrationsAsync instead.

New Features

Added the option to list migration operations which will be applied as raw sql via ListMigrationOperationsAsRawSql and ListMigrationOperationsAsRawSqlAsync context methods.

Can be useful to check generated sql scripts which will be executed to update the model or to check if migrations needs to be applied.


image


Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EFCore.AutomaticMigrations.NetTopologySuite:

Package Downloads
Shared_DynamicPreference

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.5 10,944 4/13/2023
6.0.0 3,421 12/6/2021

Update package to spport Entity Framework Core 7.0.5.
Breaking Changes:
 ListMigrations and ListMigrationsAsync are marked as deprecated. Please use ListAppliedMigrations / ListAppliedMigrationsAsync instead
New Features:
 Added the feature to list migration operations which will be applied as raw sql via ListMigrationOperationsAsRawSql / ListMigrationOperationsAsRawSqlAsync context method.