Browse Source

Added AfterData method call to PostgresqlProvider ExecuteReturnIdentity methods.

OnDiffLogEvent doesn't fire if AfterData method is not called.
IsPrimaryKey property added to DiffLogColumnInfo in order to keep track of audit entity identifier.
pull/12/head
BurakCinar07 3 years ago
parent
commit
dd2a775d49
  1. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  2. 25
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  3. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  4. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DiffLogModel.cs
  5. 4
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -520,10 +520,13 @@ namespace SqlSugar
item.Columns = new List<DiffLogColumnInfo>();
foreach (DataColumn col in dt.Columns)
{
var sugarColumn = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it =>
it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase));
DiffLogColumnInfo addItem = new DiffLogColumnInfo();
addItem.Value = row[col.ColumnName];
addItem.ColumnName = col.ColumnName;
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it=>it.DbColumnName!=null).First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
addItem.IsPrimaryKey = sugarColumn.IsPrimarykey;
addItem.ColumnDescription = sugarColumn.ColumnDescription;
item.Columns.Add(addItem);
}
result.Add(item);

25
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -809,11 +809,13 @@ namespace SqlSugar
item.Columns = new List<DiffLogColumnInfo>();
foreach (DataColumn col in dt2.Columns)
{
var sugarColumn = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).FirstOrDefault(it =>
it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase));
DiffLogColumnInfo addItem = new DiffLogColumnInfo();
addItem.Value = row[col.ColumnName];
addItem.ColumnName = col.ColumnName;
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).FirstOrDefault(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase))?.ColumnDescription;
addItem.IsPrimaryKey = sugarColumn?.IsPrimarykey ?? false;
addItem.ColumnDescription = sugarColumn?.ColumnDescription;
item.Columns.Add(addItem);
}
result.Add(item);
@ -830,7 +832,16 @@ namespace SqlSugar
if (identity != null && identity > 0 && GetIdentityKeys().HasValue())
{
var fieldName = GetIdentityKeys().Last();
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fieldName, FieldValue = identity.ToString() });
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
{
var fieldObjectType = this.EntityInfo.Columns.FirstOrDefault(x => x.DbColumnName == fieldName)
.PropertyInfo.PropertyType;
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fieldName, FieldValue = identity.ToString(),
FieldValueConvertFunc = it => UtilMethods.ChangeType2(it, fieldObjectType) });
}
else
cons.Add(new ConditionalModel() { ConditionalType = ConditionalType.Equal, FieldName = fieldName, FieldValue = identity.ToString() });
}
else
{
@ -864,10 +875,13 @@ namespace SqlSugar
item.Columns = new List<DiffLogColumnInfo>();
foreach (DataColumn col in dt.Columns)
{
var sugarColumn = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it =>
it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase));
DiffLogColumnInfo addItem = new DiffLogColumnInfo();
addItem.Value = row[col.ColumnName];
addItem.ColumnName = col.ColumnName;
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
addItem.IsPrimaryKey = sugarColumn.IsPrimarykey;
addItem.ColumnDescription = sugarColumn.ColumnDescription;
item.Columns.Add(addItem);
}
result.Add(item);
@ -883,7 +897,8 @@ namespace SqlSugar
{
ColumnDescription = it.ColumnDescription,
ColumnName = it.DbColumnName,
Value = it.PropertyInfo.GetValue(this.InsertObjs.Last(), null)
Value = it.PropertyInfo.GetValue(this.InsertObjs.Last(), null),
IsPrimaryKey = it.IsPrimarykey
}).ToList();
return new List<DiffLogTableInfo>() { diffTable };
}

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -840,10 +840,13 @@ namespace SqlSugar
item.Columns = new List<DiffLogColumnInfo>();
foreach (DataColumn col in dt.Columns)
{
var sugarColumn = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it =>
it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase));
DiffLogColumnInfo addItem = new DiffLogColumnInfo();
addItem.Value = row[col.ColumnName];
addItem.ColumnName = col.ColumnName;
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
addItem.IsPrimaryKey = sugarColumn.IsPrimarykey;
addItem.ColumnDescription = sugarColumn.ColumnDescription;
item.Columns.Add(addItem);
}
result.Add(item);

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DiffLogModel.cs

@ -21,10 +21,11 @@ namespace SqlSugar
public string TableDescription { get; set; }
public List<DiffLogColumnInfo> Columns { get; set; }
}
public class DiffLogColumnInfo {
public class DiffLogColumnInfo
{
public string ColumnName { get; set; }
public string ColumnDescription { get; set; }
public object Value { get; set; }
public bool IsPrimaryKey { get; set; }
}
}

4
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs

@ -16,6 +16,7 @@ namespace SqlSugar
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey",this.SqlBuilder.GetTranslationColumnName(GetIdentityKeys().FirstOrDefault()));
RestoreMapping();
var result = Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()).ObjToInt();
After(sql, result);
return result;
}
public override async Task<int> ExecuteReturnIdentityAsync()
@ -26,6 +27,7 @@ namespace SqlSugar
RestoreMapping();
var obj = await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = obj.ObjToInt();
After(sql, result);
return result;
}
public override KeyValuePair<string, List<SugarParameter>> ToSql()
@ -41,6 +43,7 @@ namespace SqlSugar
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", this.SqlBuilder.GetTranslationColumnName(GetIdentityKeys().FirstOrDefault()));
RestoreMapping();
var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()) ?? "0");
After(sql, result);
return result;
}
public override async Task<long> ExecuteReturnBigIdentityAsync()
@ -50,6 +53,7 @@ namespace SqlSugar
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", this.SqlBuilder.GetTranslationColumnName(GetIdentityKeys().FirstOrDefault()));
RestoreMapping();
var result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()) ?? "0");
After(sql, result);
return result;
}

Loading…
Cancel
Save