mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Diff Log
This commit is contained in:
@@ -13,6 +13,8 @@ namespace OrmTest.Demo
|
||||
public static void Init()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
|
||||
|
||||
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||
{
|
||||
Console.Write("time:" + db.Ado.SqlExecutionTime.ToString());
|
||||
@@ -23,11 +25,11 @@ namespace OrmTest.Demo
|
||||
};
|
||||
db.Aop.OnError = (exp) =>
|
||||
{
|
||||
|
||||
|
||||
};
|
||||
db.Aop.OnExecutingChangeSql = (sql, pars) =>
|
||||
{
|
||||
return new KeyValuePair<string, SugarParameter[]>(sql,pars);
|
||||
return new KeyValuePair<string, SugarParameter[]>(sql, pars);
|
||||
};
|
||||
|
||||
db.Queryable<CMStudent>().ToList();
|
||||
@@ -39,22 +41,43 @@ namespace OrmTest.Demo
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//diff log demo
|
||||
|
||||
db.Ado.DiffLogEvent = it =>
|
||||
db.Aop.OnDiffLogEvent = it =>
|
||||
{
|
||||
var editBeforeData = it.BeforeData;
|
||||
var editAfterData = it.AfterDate;
|
||||
var sql = it.Sql;
|
||||
var parameter = it.Parameters;
|
||||
var data = it.BusinessData;
|
||||
};
|
||||
|
||||
db.Updateable<Student>().EnableDiffLogEvent().ExecuteCommand();
|
||||
|
||||
var id = db.Queryable<Student>().First().Id;
|
||||
db.Updateable<Student>(new Student()
|
||||
{
|
||||
Id = id,
|
||||
CreateTime = DateTime.Now,
|
||||
Name = "before",
|
||||
SchoolId = 1
|
||||
})
|
||||
.EnableDiffLogEvent(new { title = "update Student", Modular = 1, Operator = "admin" }).ExecuteCommand();
|
||||
|
||||
|
||||
db.Updateable<Student>(new Student()
|
||||
{
|
||||
Id = id,
|
||||
CreateTime = DateTime.Now,
|
||||
Name = "after",
|
||||
SchoolId = 2
|
||||
})
|
||||
.EnableDiffLogEvent(new { title= "update Student", Modular=1, Operator="admin" })
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace OrmTest.Models
|
||||
[SugarTable("STudent")]
|
||||
public class Student
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID",ColumnDescription ="主键")]
|
||||
public int Id { get; set; }
|
||||
public int? SchoolId { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user