diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs index ff49bd017..fe2ed16ba 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs @@ -13,7 +13,8 @@ namespace SqlSugar { InsertBuilder.IsReturnIdentity = true; PreToSql(); - string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey",this.SqlBuilder.GetTranslationColumnName(GetIdentityKeys().FirstOrDefault())); + string identityColumn = GetIdentityColumn(); + string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", this.SqlBuilder.GetTranslationColumnName(identityColumn)); RestoreMapping(); var result = Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()).ObjToInt(); After(sql, result); @@ -23,7 +24,8 @@ namespace SqlSugar { InsertBuilder.IsReturnIdentity = true; PreToSql(); - string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", this.SqlBuilder.GetTranslationColumnName(GetIdentityKeys().FirstOrDefault())); + string identityColumn = GetIdentityColumn(); + string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", this.SqlBuilder.GetTranslationColumnName(identityColumn)); RestoreMapping(); var obj = await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); var result = obj.ObjToInt(); @@ -74,5 +76,17 @@ namespace SqlSugar typeof(T).GetProperties().First(t => t.Name.ToUpper() == propertyName.ToUpper()).SetValue(result, setValue, null); return idValue > 0; } + + private string GetIdentityColumn() + { + var identityColumn = GetIdentityKeys().FirstOrDefault(); + if (identityColumn == null) + { + var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(InsertBuilder.GetTableNameString); + identityColumn = columns.First(it => it.IsIdentity || it.IsPrimarykey).DbColumnName; + } + return identityColumn; + } + } } diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugar.csproj b/Src/Asp.NetCore2/SqlSugar/SqlSugar.csproj index c00a7bc61..c882f972e 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugar.csproj @@ -2,7 +2,7 @@ netstandard2.1 - 5.1.3.29 + 5.1.3.30 sun_kai_xuan https://github.com/sunkaixuan/SqlSugar diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec index 8e87805d6..5f9dd02de 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCore.nuspec @@ -2,7 +2,7 @@ SqlSugarCore - 5.1.3.29 + 5.1.3.30 sunkaixuan 果糖大数据科技 http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCoreNoDrive.nuspec b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCoreNoDrive.nuspec index f38736e59..bbcf87cc0 100644 --- a/Src/Asp.NetCore2/SqlSugar/SqlSugarForCoreNoDrive.nuspec +++ b/Src/Asp.NetCore2/SqlSugar/SqlSugarForCoreNoDrive.nuspec @@ -2,7 +2,7 @@ SqlSugarCoreNoDrive - 5.1.3.29 + 5.1.3.30 sunkaixuan Landa http://www.apache.org/licenses/LICENSE-2.0.html