EFCore.MigrationExtensions
10.0.0
dotnet add package EFCore.MigrationExtensions --version 10.0.0
NuGet\Install-Package EFCore.MigrationExtensions -Version 10.0.0
<PackageReference Include="EFCore.MigrationExtensions" Version="10.0.0" />
<PackageVersion Include="EFCore.MigrationExtensions" Version="10.0.0" />
<PackageReference Include="EFCore.MigrationExtensions" />
paket add EFCore.MigrationExtensions --version 10.0.0
#r "nuget: EFCore.MigrationExtensions, 10.0.0"
#:package EFCore.MigrationExtensions@10.0.0
#addin nuget:?package=EFCore.MigrationExtensions&version=10.0.0
#tool nuget:?package=EFCore.MigrationExtensions&version=10.0.0
EFCore.MigrationExtensions
Adds views, synonyms, stored procedures, etc. (so-called SQL objects) to the EF model. Creates migrations, when those objects are changed. SQL objects are defined as raw SQL in C#-code or in embedded resources. They can be even generated at runtime.
All EF Core model-tracking and application features are supported:
- When SQL-objects change, migrations are generated.
- SQL-objects are applied on
Database.Migrate()orDatabase.EnsureCreated(). - Correct script is generated on
dotnet ef migrations script. - Database is updated on
dotnet ef database update.
How to use
- Call
UseSqlObjects:- either in
builder.Services.AddDbContextandDesignTimeDbContextFactory - or in
DbContext.OnConfiguring
- either in
- Create an empty
DbDesignTimeServicesin your entry point. The class should inherit fromCustomNpgsqlDesignTimeServices - Add SqlObjects to your context in
DbContext.OnModelCreating - Generate migrations / scripts / update DB as usual
Ways to add SqlObjects to the model
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//...
// Add SqlObject directly
// Order is used to define the order in which objects are created / updated in DB
const string Sql = "create or replace view migr_ext_tests.v_view_10 as select * from migr_ext_tests.my_table;";
modelBuilder.AddSqlObjects(new SqlObject(Name: "v_view_10", SqlCode: Sql) { Order = 10 });
// Add all embedded resources, placed in assembly's "Sql" folder
// Only *.sql resources are added
// There is no way to define order for embedded objects
// Use resources' names if you need to sort objects
modelBuilder.AddSqlObjects(assembly: typeof(Class1).Assembly, folder: "Sql");
}
Known limitations
- Doesn't drop deleted objects (generates non compilable code, so the developer should write drop-code himself).
- Only C# is supported
- PostgreSQL and SqlServer are supported, but any other DB can be easily added (use
EFCore.MigrationExtensions.PostgreSQLas an example)
Testing
- Open TestDataAccessLayer folder in terminal
- Set connection string at TestEntryPoint/appsettings.json
- Install dotnet-ef
dotnet tool restore
- Use the following commands to add migrations / update DB
dotnet dotnet-ef migrations add MyMigr --context TestContext --project TestDataAccessLayer.csproj --startup-project ../TestEntryPoint/TestEntryPoint.csprojdotnet dotnet-ef database update --context TestContext --project TestDataAccessLayer.csproj --startup-project ../TestEntryPoint/TestEntryPoint.csprojdotnet dotnet-ef migrations script TestMigr Meetup1 --context TestContext --project TestDataAccessLayer.csproj --startup-project ../TestEntryPoint/TestEntryPoint.csproj
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on EFCore.MigrationExtensions:
| Package | Downloads |
|---|---|
|
EFCore.MigrationExtensions.PostgreSQL
Adds views, synonyms, stored procedures, etc. (so-called SQL objects) to the EF model. Creates migrations, when those objects are changed. SQL objects are defined as raw SQL in C#-code or in embedded resources. They can be even generated at runtime. For more information refer to https://github.com/denis-tsv/EFCore.MigrationExtensions |
|
|
EFCore.MigrationExtensions.SqlServer
Adds views, synonyms, stored procedures, etc. (so-called SQL objects) to the EF model. Creates migrations, when those objects are changed. SQL objects are defined as raw SQL in C#-code or in embedded resources. They can be even generated at runtime. For more information refer to https://github.com/denis-tsv/EFCore.MigrationExtensions |
GitHub repositories
This package is not used by any popular GitHub repositories.