This commit is contained in:
sunkaixuan
2018-11-13 01:51:36 +08:00
parent 3055a3de16
commit bd6de96e4e
6 changed files with 92 additions and 11 deletions

View File

@@ -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();
}
}
}
}

View File

@@ -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; }