mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-20 10:50:48 +08:00
feat: 优化orm 批量插入
This commit is contained in:
@@ -171,11 +171,21 @@ namespace ThingsGateway.SqlSugar
|
||||
else
|
||||
{
|
||||
var count = list.FirstOrDefault().Value.Item2?.Count;
|
||||
if(count==1)
|
||||
{
|
||||
var row = list.GetRows(0).ToDictionary(a => a.ColumnName, a => a.Value);
|
||||
cmd.CommandText = this.Context.InsertableT(row).AS(tableName).ToSqlString().Replace(";SELECT LAST_INSERT_ROWID();", "");
|
||||
TransformInsertCommand(cmd);
|
||||
i += await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
|
||||
return i;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
var row = list.GetRows(0).ToDictionary(a => a.ColumnName, a => a.Value);
|
||||
cmd.CommandText = this.Context.InsertableT(row).AS(tableName).ToSql().Key.Replace(";SELECT LAST_INSERT_ROWID();", "");
|
||||
}
|
||||
|
||||
TransformInsertCommand(cmd);
|
||||
if (count > 0)
|
||||
{
|
||||
@@ -292,6 +302,18 @@ namespace ThingsGateway.SqlSugar
|
||||
else
|
||||
{
|
||||
var count = list.FirstOrDefault().Value.Item2?.Count;
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
var row = list.GetRows(0).ToDictionary(a => a.ColumnName, a => a.Value);
|
||||
cmd.CommandText = this.Context.UpdateableT(row)
|
||||
.WhereColumns(whereColumns)
|
||||
.UpdateColumns(updateColumns)
|
||||
.AS(tableName).ToSqlString();
|
||||
i += await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
|
||||
return i;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
var row = list.GetRows(0).ToDictionary(a => a.ColumnName, a => a.Value);
|
||||
|
@@ -31,7 +31,7 @@ namespace ThingsGateway.SqlSugar
|
||||
{
|
||||
// 单条插入
|
||||
var columnValues = string.Join(",", DbColumnInfoList.Select(it =>
|
||||
base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName)));
|
||||
base.GetDbColumn(it, $"{Builder.SqlParameterKeyWord}{it.DbColumnName}")));
|
||||
|
||||
ActionMinDate();
|
||||
return string.Format(SqlTemplate, GetTableNameString, columnNames, columnValues);
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.11.85</PluginVersion>
|
||||
<ProPluginVersion>10.11.85</ProPluginVersion>
|
||||
<DefaultVersion>10.11.85</DefaultVersion>
|
||||
<PluginVersion>10.11.86</PluginVersion>
|
||||
<ProPluginVersion>10.11.86</ProPluginVersion>
|
||||
<DefaultVersion>10.11.86</DefaultVersion>
|
||||
<AuthenticationVersion>10.11.6</AuthenticationVersion>
|
||||
<SourceGeneratorVersion>10.11.6</SourceGeneratorVersion>
|
||||
<NET8Version>8.0.20</NET8Version>
|
||||
|
Reference in New Issue
Block a user