34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
|
using ShardingCore.Helpers;
|
|
using ShardingCore.Sharding.Abstractions;
|
|
|
|
namespace Sample.Migrations.EFCores
|
|
{
|
|
/// <summary>
|
|
/// https://github.com/Coldairarrow/EFCore.Sharding/blob/master/src/EFCore.Sharding.SqlServer/ShardingSqlServerMigrationsSqlGenerator.cs
|
|
/// </summary>
|
|
public class ShardingSqlServerMigrationsSqlGenerator<TShardingDbContext> : SqlServerMigrationsSqlGenerator where TShardingDbContext:DbContext,IShardingDbContext
|
|
{
|
|
public ShardingSqlServerMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies, IRelationalAnnotationProvider migrationsAnnotations) : base(dependencies, migrationsAnnotations)
|
|
{
|
|
}
|
|
protected override void Generate(
|
|
MigrationOperation operation,
|
|
IModel model,
|
|
MigrationCommandListBuilder builder)
|
|
{
|
|
var oldCmds = builder.GetCommandList().ToList();
|
|
base.Generate(operation, model, builder);
|
|
var newCmds = builder.GetCommandList().ToList();
|
|
var addCmds = newCmds.Where(x => !oldCmds.Contains(x)).ToList();
|
|
|
|
MigrationHelper.Generate<TShardingDbContext>(operation, builder, Dependencies.SqlGenerationHelper, addCmds);
|
|
}
|
|
}
|
|
}
|