SqlSugar/Src/Asp.Net/SqlServerTest/Demos/9_Aop.cs

60 lines
1.5 KiB
C#
Raw Normal View History

2018-11-13 00:35:42 +08:00
using OrmTest.Models;
using SqlSugar;
2017-09-19 00:29:30 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.Demo
{
public class Aop
{
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
db.Aop.OnLogExecuted = (sql, pars) =>
{
2018-11-13 00:07:07 +08:00
Console.Write("time:" + db.Ado.SqlExecutionTime.ToString());
2017-09-19 00:29:30 +08:00
};
db.Aop.OnLogExecuting = (sql, pars) =>
{
};
db.Aop.OnError = (exp) =>
{
};
db.Aop.OnExecutingChangeSql = (sql, pars) =>
{
return new KeyValuePair<string, SugarParameter[]>(sql,pars);
};
db.Queryable<CMStudent>().ToList();
try
{
db.Queryable<CMStudent>().AS(" ' ").ToList();
}
catch (Exception)
{
}
2018-11-13 00:35:42 +08:00
//diff log demo
db.Ado.DiffLogEvent = it =>
{
var editBeforeData = it.BeforeData;
var editAfterData = it.AfterDate;
var sql = it.Sql;
var parameter = it.Parameters;
};
db.Updateable<Student>().EnableDiffLogEvent().ExecuteCommand();
2017-09-19 00:29:30 +08:00
}
}
}