From 5fdbdfec82bf41c2b8b5273eb7c8230552c1aef8 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 8 Nov 2024 14:28:53 +0800 Subject: [PATCH] =?UTF-8?q?json=20=E5=88=97=E6=9B=B4=E6=96=B0=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/TrialSiteUser/TrialConfigService.cs | 1 + IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs | 2 +- .../Repository/ICommandRepository.cs | 2 +- IRaCIS.Core.Infra.EFCore/Repository/Repository.cs | 10 ++++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs index 43aea96aa..384dc9a7d 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs @@ -911,6 +911,7 @@ namespace IRaCIS.Core.Application _mapper.Map(trialConfig, trialInfo); trialInfo.UpdateTime = DateTime.Now; + _trialRepository.MarkAsModified(trialInfo, nameof(trialInfo.TrialObjectNameList)); //await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialConfig.TrialId && t.IsSigned == false, u => new ReadingQuestionCriterionTrial() { CriterionModalitys = trialConfig.Modalitys }); diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 067ef3728..2349455d9 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -72,7 +72,7 @@ public class IRaCISDBContext : DbContext modelBuilder.Entity(entity => { entity.Property(e => e.TrialObjectNameList).HasConversion(v => v == null ? "[]" : JsonConvert.SerializeObject(v), - v => string.IsNullOrEmpty(v) ? null : JsonConvert.DeserializeObject>(v)); + v => string.IsNullOrEmpty(v) ? new List() : JsonConvert.DeserializeObject>(v)); }); #region pgsql codefirst 配置 暂时屏蔽 diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 20c3f3237..4de2f0c46 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -73,7 +73,7 @@ namespace IRaCIS.Core.Infra.EFCore #endregion - + void MarkAsModified(TFrom entity, string propertyName); } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 98b87f116..300fe9ef1 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -4,6 +4,7 @@ using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Query; using Microsoft.Extensions.Localization; @@ -445,6 +446,15 @@ namespace IRaCIS.Core.Infra.EFCore #endregion + public void MarkAsModified(TFrom entity, string propertyName) + { + // 获取属性的元数据 + var entry = _dbContext.Entry(entity); + + // 设置指定属性为已修改 + entry.Property(propertyName).IsModified = true; + } + #region 异步查询