mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-20 09:28:53 +08:00
Compare commits
5 Commits
32d83ec599
...
68b890ad9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68b890ad9e | ||
|
|
2d5710c96f | ||
|
|
ba48aaf672 | ||
|
|
ab8ec39f77 | ||
|
|
b099fa6dbc |
@ -200,7 +200,7 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in insertData)
|
||||
{
|
||||
this._Context.Insertable(insertData).ExecuteCommandIdentityIntoEntity();
|
||||
this._Context.Insertable(item).ExecuteCommandIdentityIntoEntity();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@ -39,5 +39,6 @@ namespace SqlSugar
|
||||
public DbType? DatabaseModel { get;set; }
|
||||
public bool ClickHouseEnableFinal { get; set; }
|
||||
public bool EnableJsonb { get; set; }
|
||||
public PostgresIdentityStrategy PostgresIdentityStrategy { get; set; } = PostgresIdentityStrategy.Serial; // 兼容性处理,默认使用Serial
|
||||
}
|
||||
}
|
||||
|
||||
14
Src/Asp.NetCore2/SqlSugar/Enum/PostgresIdentityStrategy.cs
Normal file
14
Src/Asp.NetCore2/SqlSugar/Enum/PostgresIdentityStrategy.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SqlSugar
|
||||
{
|
||||
public enum PostgresIdentityStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// NEXTVAL() function
|
||||
/// </summary>
|
||||
Serial = 1,
|
||||
/// <summary>
|
||||
/// 自增长,PGSQL10+版本最佳实践
|
||||
/// </summary>
|
||||
Identity = 2
|
||||
}
|
||||
}
|
||||
@ -485,6 +485,7 @@ WHERE tgrelid = '"+tableName+"'::regclass");
|
||||
{
|
||||
List<string> columnArray = new List<string>();
|
||||
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
||||
var identityStrategy = this.Context.CurrentConnectionConfig.MoreSettings?.PostgresIdentityStrategy;
|
||||
foreach (var item in columns)
|
||||
{
|
||||
string columnName = item.DbColumnName;
|
||||
@ -507,6 +508,8 @@ WHERE tgrelid = '"+tableName+"'::regclass");
|
||||
string primaryKey = null;
|
||||
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName.ToLower(isAutoToLowerCodeFirst)), dataType, dataSize, nullType, primaryKey, "");
|
||||
if (item.IsIdentity)
|
||||
{
|
||||
if(identityStrategy != PostgresIdentityStrategy.Identity)
|
||||
{
|
||||
if (dataType?.ToLower() == "int")
|
||||
{
|
||||
@ -520,6 +523,13 @@ WHERE tgrelid = '"+tableName+"'::regclass");
|
||||
string identityDataType = "serial" + length;
|
||||
addItem = addItem.Replace(dataType, identityDataType);
|
||||
}
|
||||
else
|
||||
{
|
||||
string length = dataType.Substring(dataType.Length - 1);
|
||||
string identityDataType = "INT" + length + " GENERATED BY DEFAULT AS IDENTITY";
|
||||
addItem = addItem.Replace(dataType, identityDataType);
|
||||
}
|
||||
}
|
||||
columnArray.Add(addItem);
|
||||
}
|
||||
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName.ToLower(isAutoToLowerCodeFirst)), string.Join(",\r\n", columnArray));
|
||||
|
||||
@ -900,7 +900,8 @@ namespace SqlSugar
|
||||
EnableILike=it.MoreSettings.EnableILike,
|
||||
ClickHouseEnableFinal=it.MoreSettings.ClickHouseEnableFinal,
|
||||
PgSqlIsAutoToLowerSchema=it.MoreSettings.PgSqlIsAutoToLowerSchema,
|
||||
EnableJsonb=it.MoreSettings.EnableJsonb
|
||||
EnableJsonb=it.MoreSettings.EnableJsonb,
|
||||
PostgresIdentityStrategy = it.MoreSettings.PostgresIdentityStrategy
|
||||
|
||||
},
|
||||
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
|
||||
|
||||
Loading…
Reference in New Issue
Block a user