软删除修改--pre
parent
9bd0a23734
commit
4330afd683
|
@ -5,9 +5,6 @@ namespace IRaCIS.Core.Domain.Models;
|
||||||
public partial class TrialStatusDetail : BaseAddAuditEntity
|
public partial class TrialStatusDetail : BaseAddAuditEntity
|
||||||
{
|
{
|
||||||
#region 导航属性
|
#region 导航属性
|
||||||
[JsonIgnore]
|
|
||||||
public List<EnrollDetail> IntoGroupDetails { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Trial Trial { get; set; }
|
public Trial Trial { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -3,6 +3,7 @@ using IRaCIS.Core.Domain.Models;
|
||||||
using IRaCIS.Core.Infra.EFCore.Common;
|
using IRaCIS.Core.Infra.EFCore.Common;
|
||||||
using IRaCIS.Core.Infrastructure.Encryption;
|
using IRaCIS.Core.Infrastructure.Encryption;
|
||||||
using IRaCIS.Core.Infrastructure.Extention;
|
using IRaCIS.Core.Infrastructure.Extention;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
@ -77,11 +78,11 @@ public class IRaCISDBContext : DbContext
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Trial>(entity =>
|
modelBuilder.Entity<Trial>(entity =>
|
||||||
{
|
{
|
||||||
//项目术语配置
|
//项目术语配置
|
||||||
entity.OwnsMany(x => x.TrialObjectNameList, ownedNavigationBuilder =>
|
entity.OwnsMany(x => x.TrialObjectNameList, ownedNavigationBuilder =>
|
||||||
{
|
{
|
||||||
ownedNavigationBuilder.ToJson() ;
|
ownedNavigationBuilder.ToJson();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -144,13 +145,54 @@ public class IRaCISDBContext : DbContext
|
||||||
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
//软删除筛选器通常依赖于实体模型的完整定义(例如属性映射、继承关系等)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||||
{
|
{
|
||||||
// 软删除配置
|
// 软删除配置
|
||||||
if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType))
|
if (typeof(ISoftDelete).IsAssignableFrom(entityType.ClrType))
|
||||||
{
|
{
|
||||||
entityType.AddSoftDeleteQueryFilter();
|
//entityType.AddSoftDeleteQueryFilter();
|
||||||
|
|
||||||
|
// 动态创建表达式:e => e.IsDeleted==false
|
||||||
|
var parameter = Expression.Parameter(entityType.ClrType, "e");
|
||||||
|
var property = Expression.Property(parameter, nameof(ISoftDelete.IsDeleted));
|
||||||
|
var filter = Expression.Lambda(
|
||||||
|
Expression.Equal(property, Expression.Constant(false)),
|
||||||
|
parameter);
|
||||||
|
|
||||||
|
// 应用全局查询筛选器
|
||||||
|
modelBuilder.Entity(entityType.ClrType).HasQueryFilter(filter);
|
||||||
|
|
||||||
|
//Console.WriteLine($"实体应用软删除:{entityType.ClrType.Name}");
|
||||||
|
|
||||||
|
}
|
||||||
|
foreach (var navigation in entityType.GetNavigations())
|
||||||
|
{
|
||||||
|
|
||||||
|
if (navigation.IsCollection) continue;
|
||||||
|
|
||||||
|
// 配置基于导航属性的软删除查询筛选器
|
||||||
|
if (typeof(ISoftDelete).IsAssignableFrom(navigation.TargetEntityType.ClrType))
|
||||||
|
{
|
||||||
|
var clrType = entityType.ClrType;
|
||||||
|
var targetType = navigation.TargetEntityType.ClrType;
|
||||||
|
|
||||||
|
//e => e.Subject.IsDeleted==false
|
||||||
|
var parameterNav = Expression.Parameter(clrType, "e");
|
||||||
|
var navigationProperty = Expression.Property(parameterNav, navigation.Name);
|
||||||
|
var navigationFilter = Expression.Equal(
|
||||||
|
Expression.Property(navigationProperty, nameof(ISoftDelete.IsDeleted)),
|
||||||
|
Expression.Constant(false));
|
||||||
|
|
||||||
|
var filterNav = Expression.Lambda(navigationFilter, parameterNav);
|
||||||
|
|
||||||
|
modelBuilder.Entity(clrType).HasQueryFilter(filterNav);
|
||||||
|
|
||||||
|
//Console.WriteLine($"实体应用软删除:{entityType.ClrType.Name} 导航属性{filterNav}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof(Entity).IsAssignableFrom(entityType.ClrType))
|
if (typeof(Entity).IsAssignableFrom(entityType.ClrType))
|
||||||
|
@ -588,7 +630,7 @@ public class TestLength : Entity
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[StringLength(1000)]
|
[StringLength(1000)]
|
||||||
public string[] StringList { get; set; }=new string[] { };
|
public string[] StringList { get; set; } = new string[] { };
|
||||||
|
|
||||||
public List<DateTime> DateTimeList { get; set; } = new List<DateTime>();
|
public List<DateTime> DateTimeList { get; set; } = new List<DateTime>();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration
|
||||||
//对于全局修改的任务而言,会关联多个全局访视阅片结果(因为同一个访视结果,会被多个全局修改)
|
//对于全局修改的任务而言,会关联多个全局访视阅片结果(因为同一个访视结果,会被多个全局修改)
|
||||||
|
|
||||||
//subject 删除了,但是任务没删除,导致的查询问题
|
//subject 删除了,但是任务没删除,导致的查询问题
|
||||||
builder.HasQueryFilter(b => b.Subject.IsDeleted == false);
|
//builder.HasQueryFilter(b => b.Subject.IsDeleted == false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue