From da09f66a719436c509d1e9a6b3548e5d75a30f88 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 14 Apr 2022 17:49:27 +0800 Subject: [PATCH] d --- .../Service/Common/DTO/DictionaryModel.cs | 2 +- .../Service/Common/DictionaryService.cs | 4 ++++ .../Repository/Repository.cs | 16 ++++------------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs index 454bbddb0..6f5bab8dd 100644 --- a/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs +++ b/IRaCIS.Core.Application/Service/Common/DTO/DictionaryModel.cs @@ -42,7 +42,7 @@ namespace IRaCIS.Application.Contracts //有父亲 就有值 - public Guid? ParentId { get; set; } + public Guid ParentId { get; set; } public bool IsEnable { get; set; } diff --git a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs index af6ccffb7..de7f053be 100644 --- a/IRaCIS.Core.Application/Service/Common/DictionaryService.cs +++ b/IRaCIS.Core.Application/Service/Common/DictionaryService.cs @@ -62,6 +62,10 @@ namespace IRaCIS.Application.Services if (addOrEditBasic.Id == null) { var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic); + + await _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Empty, + u => new Dictionary() { ParentId = null }); + return ResponseOutput.Ok(entity.Id.ToString()); } else diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 915f39d07..43ee744dd 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -66,28 +66,20 @@ namespace IRaCIS.Core.Infra.EFCore //以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写 var properties = type.GetProperties().Where(t=>t.Name!="Id"); - //.Where(t => !t.GetCustomAttributes().Any(c => c.GetType() == typeof(NotMappedAttribute))) - //.Where(t => !t.PropertyType.IsGenericType); + - string[] strSqlNames = properties - .Select(p => $"[{p.Name}]").ToArray(); + string strSqlName = string.Join(",", properties.Select(p => $"[{p.Name}]").ToArray()); - string strSqlName = string.Join(",", strSqlNames); - string[] strSqlValues = properties.Select(P => $"@{P.Name}").ToArray(); - string strSqlValue = string.Join(",", strSqlValues); + string strSqlValue = string.Join(",", properties.Select(P => $"@{P.Name}").ToArray()); - // strSql得到的 sql语句为insert into testModel ( [ID],[Name],[QQ],[Email] ) values (@ID,@Name,@QQ,@Email) string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")"; //para Sql是参数 - SqlParameter[] para = properties - .Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray(); + SqlParameter[] para = properties.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray(); _dbContext.Database.ExecuteSqlRaw(strSql, para); - //测试还是有问题 NotMapped 会失效 - //await quey.BulkInsertAsync(new List() { entity as Dictionary }); return entity; } else