Uat_Study
parent
576c1bf7e9
commit
da09f66a71
|
@ -42,7 +42,7 @@ namespace IRaCIS.Application.Contracts
|
||||||
|
|
||||||
|
|
||||||
//有父亲 就有值
|
//有父亲 就有值
|
||||||
public Guid? ParentId { get; set; }
|
public Guid ParentId { get; set; }
|
||||||
|
|
||||||
public bool IsEnable { get; set; }
|
public bool IsEnable { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,10 @@ namespace IRaCIS.Application.Services
|
||||||
if (addOrEditBasic.Id == null)
|
if (addOrEditBasic.Id == null)
|
||||||
{
|
{
|
||||||
var entity = await _dicRepository.InsertDictionaryAsync(addOrEditBasic);
|
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());
|
return ResponseOutput.Ok(entity.Id.ToString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -66,28 +66,20 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
|
|
||||||
//以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写
|
//以下是不要ID这个字段的 比如自增列ID 就不能像上名那样写
|
||||||
var properties = type.GetProperties().Where(t=>t.Name!="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(",", strSqlNames);
|
string strSqlName = string.Join(",", properties.Select(p => $"[{p.Name}]").ToArray());
|
||||||
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 + ")";
|
string strSql = $"insert into {nameof(Dictionary)} ( " + strSqlName + " ) values (" + strSqlValue + ")";
|
||||||
|
|
||||||
//para Sql是参数
|
//para Sql是参数
|
||||||
SqlParameter[] para = properties
|
SqlParameter[] para = properties.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray();
|
||||||
.Select(p => new SqlParameter($"@{p.Name}", p.GetValue(from, null))).ToArray();
|
|
||||||
|
|
||||||
|
|
||||||
_dbContext.Database.ExecuteSqlRaw(strSql, para);
|
_dbContext.Database.ExecuteSqlRaw(strSql, para);
|
||||||
|
|
||||||
//测试还是有问题 NotMapped 会失效
|
|
||||||
//await quey.BulkInsertAsync(new List<Dictionary>() { entity as Dictionary });
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue