EntityFrameworkCore.SqlServer.Seeding.Tool 0.9.4

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global EntityFrameworkCore.SqlServer.Seeding.Tool --version 0.9.4
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local EntityFrameworkCore.SqlServer.Seeding.Tool --version 0.9.4
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=EntityFrameworkCore.SqlServer.Seeding.Tool&version=0.9.4
nuke :add-package EntityFrameworkCore.SqlServer.Seeding.Tool --version 0.9.4

This package allows you to seed the data to SQL Server database using pure SQL scripts but in a managed fashion similar to Entity Framework Core migrations.

Invoking the seeding

Install NuGet package to your project

dotnet add package EntityFrameworkCore.SqlServer.Seeding

Add script seeding to services collection and supply the connection string to the database

public void ConfigureServices(IServiceCollection services)
{
	...
	services.AddScriptSeeding(Configuration.GetConnectionString("EmployeesDatabase"));
	...
}

Invoke the seeding in the pipeline by supplying the assembly where your scripts are sitting along with a folder under which scripts sit under project tree. The default value is "Seedings"

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
	...
    app.SeedFromScripts(typeof(EmployeesDatabaseContext).Assembly, "Seedings");
	...
}

Adding new seeding script

As a first step you need to install global tool EntityFrameworkCore.SqlServer.Seeding.Tool which will help you add the seeding script to the project where you want to have your seeding scripts. I usually keep them together with migrations as a part of infrastructure.

dotnet tool install --global EntityFrameworkCore.SqlServer.Seeding.Tool 

From a command line (cmd, PowerShell, bash…) navigate to project folder where you want your scripts to sit. Simply add the script by invoking the previously installed global tool

seeding add "Add_Initial_Employees" -o Seedings

This will create new file under Seedings folder in your project tree. Once you run the main project, seeding files will be executed and recorded in __SeedingHistory table

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

This package has no dependencies.

Version Downloads Last updated
5.0.0 464 5/8/2021
0.9.5 492 10/24/2020
0.9.4 455 10/17/2020