From 611480195933719300f7bb1d6d4f630fa56d9153 Mon Sep 17 00:00:00 2001 From: hang <87227557@qq.com> Date: Mon, 19 Jan 2026 23:46:44 +0800 Subject: [PATCH] =?UTF-8?q?efcore=20=E9=87=8D=E5=A4=8D=E8=B7=9F=E8=B8=AA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=95=B0=E7=BB=84json=E5=88=97=EF=BC=8C=E6=97=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=A5=87=E6=80=AA=E9=97=AE=E9=A2=98=E5=8F=91=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRaCIS.Core.Application.xml | 35 ++++++++++++ IRaCIS.Core.Application/TestService.cs | 53 ++++++++++++++++++- .../Repository/IRaCISContextExtension.cs | 7 ++- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index b92dc6a5f..5d3df0cc5 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -9497,6 +9497,16 @@ 评估原因 + + + 数值类型 + + + + + 自定义单位 + + 问题类型 @@ -9642,6 +9652,11 @@ 数值类型 + + + 自定义单位 + + 类型 @@ -9782,6 +9797,16 @@ 字典code + + + 自定义单位 + + + + + 数值类型 + + 是否存在疾病 @@ -10697,6 +10722,16 @@ 问题英文名称 + + + 数值类型 + + + + + 自定义单位 + + 排序 diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index 0a2ffbadc..8ecfcbd5f 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -38,6 +38,7 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Processing; using System.Collections.Concurrent; +using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Globalization; using System.IO; @@ -75,6 +76,56 @@ namespace IRaCIS.Core.Application.Service { public static int IntValue = 100; + public async Task EfcoreTest11() + { + //更 + await _trialRepository.UpdatePartialFromQueryAsync(t => t.Id == Guid.Parse("08de572a-55c6-6503-0242-0a0001000000"), t => new Trial() { CreateTime = DateTime.Now },true); + + await _trialRepository.UpdatePartialFromQueryAsync(t => t.Id == Guid.Parse("08DDACB9-B6CA-F21C-0242-0A0001000000"), t => new Trial() { CreateTime = DateTime.Now },true); + + return ResponseOutput.Ok(); + + } + + public class ModelVerifyCommand + { + public int? IntNUllValue { get; set; } + public int IntValue { get; set; } + + public string StringValue { get; set; } + + public string? StringNUllValue { get; set; } + + public string StringBackDefaultValue { get; set; } = string.Empty; + + public Guid GuidValue { get; set; } = NewId.NextSequentialGuid(); + + public Guid? GuidNUllValue { get; set; } + + [NotDefault] + public Guid GuidValueNotDefault { get; set; } + + + public bool BoolValue { get; set; } + + public bool? BoolNUllValue { get; set; } + + public DateTime DateTimeValue { get; set; } + + public DateTime? DateTimeNUllValue { get; set; } + } + + + //创建一个模型验证的方法 + [AllowAnonymous] + [HttpPost] + public async Task PostModelVerify(ModelVerifyCommand modelVerify) + { + + return ResponseOutput.Ok(modelVerify); + + } + [AllowAnonymous] public async Task DealIVUSOCTDicomTag(string subjectCode, bool? isUploadOss) { @@ -102,7 +153,7 @@ namespace IRaCIS.Core.Application.Service { Console.WriteLine(item.Path); - await using var stream = await _IOSSService.GetStreamFromOSSAsync(item.Path); + await using var stream = await _IOSSService.GetStreamFromOSSAsync(item.Path); var dicomFile = DicomFile.Open(stream, FileReadOption.ReadLargeOnDemand); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 71fb563e1..ebd59fe2a 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -119,7 +119,10 @@ namespace IRaCIS.Core.Infra.EFCore /// EntityState.Detached的实体 修改 部分字段 public static void EntityModifyPartialFiled(this IRaCISDBContext _dbContext, T waitModifyEntity, Expression> updateFactory) where T : Entity { - var entityEntry = _dbContext.Entry(waitModifyEntity); + //解决重复跟踪问题 + var tracked = _dbContext.ChangeTracker.Entries().FirstOrDefault(e => e.Entity.Id.Equals(waitModifyEntity.Id)); + var entityEntry = tracked?? _dbContext.Entry(waitModifyEntity); + //entityEntry.State = EntityState.Detached; var list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name) @@ -134,7 +137,7 @@ namespace IRaCIS.Core.Infra.EFCore foreach (PropertyInfo prop in list) { - _dbContext.Entry(waitModifyEntity).Property(prop.Name).IsModified = true; + entityEntry.Property(prop.Name).IsModified = true; object value = prop.GetValue(applyObj); prop.SetValue(waitModifyEntity, value);