mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-06 16:30:52 +08:00
update
8
AOP.md
8
AOP.md
@@ -8,10 +8,10 @@ FreeSql 支持简单的类似功能:
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
fsql.Aop.CurdAfter += (s, e) => {
|
fsql.Aop.CurdAfter += (s, e) => {
|
||||||
if (e.ElapsedMilliseconds > 200) {
|
if (e.ElapsedMilliseconds > 200) {
|
||||||
//记录日志
|
//记录日志
|
||||||
//发送短信给负责人
|
//发送短信给负责人
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
38
骚操作.md
38
骚操作.md
@@ -170,8 +170,8 @@ fsql.Select<Goods>().IncludeMany(a => a.Comment.Take(10));
|
|||||||
```csharp
|
```csharp
|
||||||
//定义临时类,也可以是 Dto 类
|
//定义临时类,也可以是 Dto 类
|
||||||
class Dto {
|
class Dto {
|
||||||
public int TypeId { get; set; }
|
public int TypeId { get; set; }
|
||||||
public List<Goods > GoodsList { get; set; }
|
public List<Goods > GoodsList { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询 Goods 商品表,分类1、分类2、分类3 各10条数据
|
//查询 Goods 商品表,分类1、分类2、分类3 各10条数据
|
||||||
@@ -427,16 +427,16 @@ fsql.Aop.CurdAfter += (s, e) => {
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
fsql.Aop.AuditValue += (s, e) => {
|
fsql.Aop.AuditValue += (s, e) => {
|
||||||
if (e.Column.CsType == typeof(long)
|
if (e.Column.CsType == typeof(long)
|
||||||
&& e.Property.GetCustomAttribute<SnowflakeAttribute>(false) != null
|
&& e.Property.GetCustomAttribute<SnowflakeAttribute>(false) != null
|
||||||
&& e.Value?.ToString() == 0)
|
&& e.Value?.ToString() == 0)
|
||||||
e.Value = new Snowflake().GetId();
|
e.Value = new Snowflake().GetId();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Order {
|
class Order {
|
||||||
[Snowflake]
|
[Snowflake]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -455,19 +455,19 @@ using FreeSql;
|
|||||||
|
|
||||||
using (var conn = new SqlConnection(...))
|
using (var conn = new SqlConnection(...))
|
||||||
{
|
{
|
||||||
IFreeSql fsql = conn.GetIFreeSql();
|
IFreeSql fsql = conn.GetIFreeSql();
|
||||||
fsql.CodeFirst.IsNoneCommandParameter = true;
|
fsql.CodeFirst.IsNoneCommandParameter = true;
|
||||||
fsql.CodeFirst.IsSyncStructureToUpper = true;
|
fsql.CodeFirst.IsSyncStructureToUpper = true;
|
||||||
fsql.Aop.CommandBefore += (_, e) => Trace.WriteLine(e.Command.CommandText);
|
fsql.Aop.CommandBefore += (_, e) => Trace.WriteLine(e.Command.CommandText);
|
||||||
//以上整个程序只需要设置一次
|
//以上整个程序只需要设置一次
|
||||||
|
|
||||||
conn.Select<T>().Where(...).ToList();
|
conn.Select<T>().Where(...).ToList();
|
||||||
|
|
||||||
conn.Insert(new T {}).ExecuteAffrows();
|
conn.Insert(new T {}).ExecuteAffrows();
|
||||||
conn.Update().SetSource(new T {}).ExecuteAffrows();
|
conn.Update().SetSource(new T {}).ExecuteAffrows();
|
||||||
conn.InsertOrUpdate().SetSource(new T {}).ExecuteAffrows();
|
conn.InsertOrUpdate().SetSource(new T {}).ExecuteAffrows();
|
||||||
|
|
||||||
conn.Delete<T>().Where(...).ExecuteAffrows();
|
conn.Delete<T>().Where(...).ExecuteAffrows();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user