修改上传逻辑
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Test
|
||||
{
|
||||
@@ -21,7 +17,7 @@ namespace IRaCIS.Core.Test
|
||||
.Where(
|
||||
property => property.ClrType == typeof(string))))
|
||||
{
|
||||
property.Builder.HasMaxLength(200);
|
||||
property.Builder.HasMaxLength(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
namespace IRaCIS.Core.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// 这种方式不行
|
||||
/// </summary>
|
||||
public class NoForeignKeyConvention : IModelFinalizingConvention
|
||||
{
|
||||
public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
|
||||
{
|
||||
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
|
||||
{
|
||||
foreach (var foreignKey in entityType.GetForeignKeys())
|
||||
{
|
||||
// 设置删除行为为 NoAction,避免生成外键约束
|
||||
foreignKey.Builder.OnDelete(DeleteBehavior.NoAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-15
@@ -1,10 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace IRaCIS.Core.Test
|
||||
{
|
||||
@@ -15,16 +11,10 @@ namespace IRaCIS.Core.Test
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder)
|
||||
protected override void Generate(Microsoft.EntityFrameworkCore.Migrations.Operations.CreateTableOperation operation, IModel? model, MigrationCommandListBuilder builder, bool terminate = true)
|
||||
{
|
||||
if (operation is AddForeignKeyOperation || operation is DropForeignKeyOperation)
|
||||
{
|
||||
// 跳过外键的生成
|
||||
return;
|
||||
}
|
||||
|
||||
base.Generate(operation, model, builder);
|
||||
operation.ForeignKeys.Clear();
|
||||
base.Generate(operation, model, builder, terminate);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user