mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
- 优化 IInsertOrUpdate SetSource tempPrimary 自增的忽略插入;
This commit is contained in:
@ -50,10 +50,15 @@ namespace FreeSql.Custom.SqlServer
|
||||
))).Append(" \r\n");
|
||||
|
||||
cols = _table.Columns.Values.Where(a => a.Attribute.CanInsert == true);
|
||||
if (_tempPrimarys.Any(b => b.Attribute.IsIdentity) == false) cols = cols.Where(a => a.Attribute.IsIdentity == false || string.IsNullOrEmpty(a.DbInsertValue) == false);
|
||||
if (cols.Any())
|
||||
sb.Append("WHEN NOT MATCHED THEN \r\n")
|
||||
.Append(" insert (").Append(string.Join(", ", cols.Select(a => _commonUtils.QuoteSqlName(a.Attribute.Name)))).Append(") \r\n")
|
||||
.Append(" values (").Append(string.Join(", ", cols.Select(a => $"t2.{_commonUtils.QuoteSqlName(a.Attribute.Name)}"))).Append(");");
|
||||
.Append(" values (").Append(string.Join(", ", cols.Select(a =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(a.DbInsertValue) == false) return a.DbInsertValue;
|
||||
return $"t2.{_commonUtils.QuoteSqlName(a.Attribute.Name)}";
|
||||
}))).Append(");");
|
||||
|
||||
if (IdentityColumn != null) sb.Append(";\r\nSET IDENTITY_INSERT ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(" OFF;");
|
||||
|
||||
|
Reference in New Issue
Block a user