Uat_Study
hang 2022-04-14 17:49:27 +08:00
parent 576c1bf7e9
commit da09f66a71
3 changed files with 9 additions and 13 deletions

View File

@ -42,7 +42,7 @@ namespace IRaCIS.Application.Contracts
//有父亲 就有值
public Guid? ParentId { get; set; }
public Guid ParentId { get; set; }
public bool IsEnable { get; set; }

View File

@ -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

View File

@ -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<Dictionary>() { entity as Dictionary });
return entity;
}
else