-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.IO; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.EntityFrameworkCore.Migrations.Design; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace CommandLine | ||
{ | ||
public class CustomTools | ||
{ | ||
public static void AddMigration(string migrationName) | ||
{ | ||
var projectDir = Directory.GetCurrentDirectory(); | ||
var rootNamespace = "ConsoleApp1"; | ||
var outputDir = "Migraitons"; | ||
|
||
#region CustomTools | ||
var db = new MyDbContext(); | ||
|
||
// Create design-time services | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddEntityFrameworkDesignTimeServices(); | ||
serviceCollection.AddDbContextDesignTimeServices(db); | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
||
// Add a migration | ||
var migrationsScaffolder = serviceProvider.GetService<IMigrationsScaffolder>(); | ||
var migration = migrationsScaffolder.ScaffoldMigration(migrationName, rootNamespace); | ||
migrationsScaffolder.Save(projectDir, migration, outputDir); | ||
#endregion | ||
} | ||
} | ||
|
||
class MyDbContext : DbContext | ||
{ | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
samples/core/Miscellaneous/CommandLine/DesignTimeServices.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.EntityFrameworkCore.Migrations.Design; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
#region DesignTimeServices | ||
class MyDesignTimeServices : IDesignTimeServices | ||
{ | ||
public void ConfigureDesignTimeServices(IServiceCollection services) | ||
=> services.AddSingleton<IMigrationsCodeGenerator, MyMigrationsCodeGenerator>(); | ||
} | ||
#endregion | ||
|
||
class MyMigrationsCodeGenerator : CSharpMigrationsGenerator | ||
{ | ||
public MyMigrationsCodeGenerator( | ||
MigrationsCodeGeneratorDependencies dependencies, | ||
CSharpMigrationsGeneratorDependencies csharpDependencies) | ||
: base(dependencies, csharpDependencies) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters