mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Demo
This commit is contained in:
parent
86aef961ee
commit
04b746f05f
@ -8,6 +8,6 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = @"DataSource=F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\Src\Asp.Net\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
public static string ConnectionString = @"DataSource=F:\GIT\SqlSugar\Src\Asp.Net\SqliteTest\DataBase\SqlSugar4xTest.sqlite";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
89
Src/Asp.Net/SqliteTest/Demos/9_Aop.cs
Normal file
89
Src/Asp.Net/SqliteTest/Demos/9_Aop.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
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.Sqlite, IsAutoCloseConnection = true });
|
||||||
|
|
||||||
|
|
||||||
|
db.Aop.OnLogExecuted = (sql, pars) =>
|
||||||
|
{
|
||||||
|
Console.Write("time:" + db.Ado.SqlExecutionTime.ToString());
|
||||||
|
};
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//diff log demo
|
||||||
|
|
||||||
|
db.Aop.OnDiffLogEvent = it =>
|
||||||
|
{
|
||||||
|
var editBeforeData = it.BeforeData;
|
||||||
|
var editAfterData = it.AfterData;
|
||||||
|
var sql = it.Sql;
|
||||||
|
var parameter = it.Parameters;
|
||||||
|
var data = it.BusinessData;
|
||||||
|
var type = it.DiffType;
|
||||||
|
var time = it.Time;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var id = db.Insertable(new Student() { Name = "beforeName" })
|
||||||
|
.EnableDiffLogEvent(new { title="add student"})
|
||||||
|
.ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
|
||||||
|
db.Updateable<Student>(new Student()
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
CreateTime = DateTime.Now,
|
||||||
|
Name = "afterName",
|
||||||
|
SchoolId = 2
|
||||||
|
})
|
||||||
|
.EnableDiffLogEvent(new { title = "update Student", Modular = 1, Operator = "admin" })
|
||||||
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
db.Deleteable<Student>(id)
|
||||||
|
.EnableDiffLogEvent(new { title = "delete student" })
|
||||||
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
//primary key guid
|
||||||
|
db.Insertable(new DataTestInfo2() { Bool1=true, Bool2=false, PK=Guid.NewGuid(), Text1="a" })
|
||||||
|
.EnableDiffLogEvent(new { title = "add DataTestInfo2" })
|
||||||
|
.ExecuteReturnIdentity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,7 @@ namespace OrmTest
|
|||||||
OrmTest.Demo.Filter.Init();
|
OrmTest.Demo.Filter.Init();
|
||||||
OrmTest.Demo.ComplexModel.Init();
|
OrmTest.Demo.ComplexModel.Init();
|
||||||
OrmTest.Demo.CodeFirst.Init();
|
OrmTest.Demo.CodeFirst.Init();
|
||||||
|
OrmTest.Demo.Aop.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
<Compile Include="Demos\6_ComplexModel.cs" />
|
<Compile Include="Demos\6_ComplexModel.cs" />
|
||||||
<Compile Include="Demos\7_Filter.cs" />
|
<Compile Include="Demos\7_Filter.cs" />
|
||||||
<Compile Include="Demos\8_JoinSql.cs" />
|
<Compile Include="Demos\8_JoinSql.cs" />
|
||||||
|
<Compile Include="Demos\9_Aop.cs" />
|
||||||
<Compile Include="Demos\DemoBase.cs" />
|
<Compile Include="Demos\DemoBase.cs" />
|
||||||
<Compile Include="Models\DataTestInfo.cs" />
|
<Compile Include="Models\DataTestInfo.cs" />
|
||||||
<Compile Include="Models\DataTestInfo2.cs" />
|
<Compile Include="Models\DataTestInfo2.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user