40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Microsoft.EntityFrameworkCore.Migrations.Internal;
|
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Microsoft.EntityFrameworkCore.Update;
|
|
using Microsoft.EntityFrameworkCore.Update.Internal;
|
|
|
|
namespace Sample.Migrations
|
|
{
|
|
/*
|
|
* @Author: xjm
|
|
* @Description:
|
|
* @Date: Sunday, 28 November 2021 21:35:45
|
|
* @Email: 326308290@qq.com
|
|
*/
|
|
[SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<挂起>")]
|
|
public class RemoveForeignKeyMigrationsModelDiffer:MigrationsModelDiffer
|
|
{
|
|
public RemoveForeignKeyMigrationsModelDiffer(IRelationalTypeMappingSource typeMappingSource, IMigrationsAnnotationProvider migrationsAnnotations, IChangeDetector changeDetector, IUpdateAdapterFactory updateAdapterFactory, CommandBatchPreparerDependencies commandBatchPreparerDependencies) : base(typeMappingSource, migrationsAnnotations, changeDetector, updateAdapterFactory, commandBatchPreparerDependencies)
|
|
{
|
|
}
|
|
|
|
public override IReadOnlyList<MigrationOperation> GetDifferences(IRelationalModel? source, IRelationalModel? target)
|
|
{
|
|
var sourceOperations = base.GetDifferences(source, target).ToList();
|
|
sourceOperations.RemoveAll(x => x is AddForeignKeyOperation || x is DropForeignKeyOperation);
|
|
foreach (var operation in sourceOperations.OfType<CreateTableOperation>())
|
|
{
|
|
operation.ForeignKeys?.Clear();
|
|
}
|
|
return sourceOperations;
|
|
}
|
|
}
|
|
} |