mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 18:34:55 +08:00
Fix PostgreSQL bulk copy identity column handling
- Modified FastestProvider to handle identity columns differently for PostgreSQL/Vastbase - Added logic to exclude identity columns from bulk copy operations for PostgreSQL - Commented out identity column restriction in PostgreSQLFastBuilder - PostgreSQL bulk copy now supports tables with identity columns by excluding them 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -99,8 +99,27 @@ namespace SqlSugar
|
|||||||
dt.Columns.Add(item.ColumnName, item.DataType);
|
dt.Columns.Add(item.ColumnName, item.DataType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool supportIdentity = true;
|
||||||
|
if (this.context.CurrentConnectionConfig.DbType == DbType.PostgreSQL || this.context.CurrentConnectionConfig.DbType == DbType.Vastbase)
|
||||||
|
{
|
||||||
|
supportIdentity = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!supportIdentity)
|
||||||
|
{
|
||||||
|
// PostgreSQL/Vastbase不支持自增主键导入
|
||||||
|
foreach (var identityColumnInfo in this.entityInfo.Columns.Where(it => it.IsIdentity))
|
||||||
|
{
|
||||||
|
if (dt.Columns.Contains(identityColumnInfo.DbColumnName))
|
||||||
|
{
|
||||||
|
dt.Columns.Remove(identityColumnInfo.DbColumnName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dt.TableName = GetTableName();
|
dt.TableName = GetTableName();
|
||||||
var columns = entityInfo.Columns;
|
var columns = supportIdentity ? entityInfo.Columns : entityInfo.Columns.Where(it => !it.IsIdentity).ToList();
|
||||||
if (columns.Where(it=>!it.IsIgnore).Count() > tempDataTable.Columns.Count)
|
if (columns.Where(it=>!it.IsIgnore).Count() > tempDataTable.Columns.Count)
|
||||||
{
|
{
|
||||||
var tempColumns = tempDataTable.Columns.Cast<DataColumn>().Select(it=>it.ColumnName);
|
var tempColumns = tempDataTable.Columns.Cast<DataColumn>().Select(it=>it.ColumnName);
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ namespace SqlSugar
|
|||||||
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(this.entityInfo.DbTableName);
|
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(this.entityInfo.DbTableName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
|
//var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
|
||||||
if (identityColumnInfo != null)
|
//if (identityColumnInfo != null)
|
||||||
{
|
//{
|
||||||
throw new Exception("PgSql bulkcopy no support identity");
|
// throw new Exception("PgSql bulkcopy no support identity");
|
||||||
}
|
//}
|
||||||
BulkCopy(dt, copyString, conn, columns);
|
BulkCopy(dt, copyString, conn, columns);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user