mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +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:
@@ -86,7 +86,7 @@ namespace SqlSugar
|
||||
List<string> uInt64TypeName = new List<string>();
|
||||
foreach (DataColumn item in tempDataTable.Columns)
|
||||
{
|
||||
if (item.DataType == typeof(UInt64))
|
||||
if (item.DataType == typeof(UInt64))
|
||||
{
|
||||
uInt64TypeName.Add(item.ColumnName);
|
||||
}
|
||||
@@ -99,8 +99,27 @@ namespace SqlSugar
|
||||
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();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
try
|
||||
{
|
||||
var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
|
||||
if (identityColumnInfo != null)
|
||||
{
|
||||
throw new Exception("PgSql bulkcopy no support identity");
|
||||
}
|
||||
//var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
|
||||
//if (identityColumnInfo != null)
|
||||
//{
|
||||
// throw new Exception("PgSql bulkcopy no support identity");
|
||||
//}
|
||||
BulkCopy(dt, copyString, conn, columns);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user