标签:only ssm not ppi app ret color dep table
继承 MigrationsModelDiffer,重载 GetDifferences 并移除 ForeignKeys
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<挂起>")] public class MigrationsModelDifferWithoutForeignKey : MigrationsModelDiffer { public MigrationsModelDifferWithoutForeignKey ([NotNull] IRelationalTypeMappingSource typeMappingSource, [NotNull] IMigrationsAnnotationProvider migrationsAnnotations, [NotNull] IChangeDetector changeDetector, [NotNull] IUpdateAdapterFactory updateAdapterFactory, [NotNull] CommandBatchPreparerDependencies commandBatchPreparerDependencies) : base(typeMappingSource, migrationsAnnotations, changeDetector, updateAdapterFactory, commandBatchPreparerDependencies) { } public override IReadOnlyList<MigrationOperation> GetDifferences(IModel source, IModel target) { var operations = base.GetDifferences(source, target); foreach (var operation in operations.OfType<CreateTableOperation>()) operation.ForeignKeys?.Clear(); return operations; } }
使用时,替换服务即可:
services.AddDbContext<MyDbContext>(options => { options.UseSqlServer(Default); options.ReplaceService<IMigrationsModelDiffer, MigrationsModelDifferWithoutForeignKey>(); });
标签:only ssm not ppi app ret color dep table
原文地址:https://www.cnblogs.com/lludcmmcdull/p/13502567.html