mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-06 00:10:55 +08:00
update
33
ADO.md
33
ADO.md
@@ -69,3 +69,36 @@ fsql.Ado.CommandFluent("dbo.GetICMaxNum")
|
|||||||
|
|
||||||
Console.WriteLine(p2.Value);
|
Console.WriteLine(p2.Value);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Ado.net 扩展方法
|
||||||
|
|
||||||
|
提供了类似 Dapper 的使用方法,FreeSql 增加了 IDbConnection/IDbTransaction 对象的扩展方法 Select/Insert/Update/Delete 实现 CRUD。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using FreeSql;
|
||||||
|
|
||||||
|
using (var conn = new SqlConnection(...))
|
||||||
|
{
|
||||||
|
//IFreeSql fsql = conn.GetIFreeSql();
|
||||||
|
//fsql.CodeFirst.IsNoneCommandParameter = true;
|
||||||
|
//fsql.CodeFirst.IsSyncStructureToUpper = true;
|
||||||
|
//fsql.Aop.CommandBefore += (_, e) => Trace.WriteLine(e.Command.CommandText);
|
||||||
|
//以上整个程序只需要设置一次
|
||||||
|
|
||||||
|
conn.Select<T>().Where(...).ToList();
|
||||||
|
|
||||||
|
conn.Insert(new T {}).ExecuteAffrows();
|
||||||
|
conn.Update().SetSource(new T {}).ExecuteAffrows();
|
||||||
|
conn.InsertOrUpdate().SetSource(new T {}).ExecuteAffrows();
|
||||||
|
|
||||||
|
conn.Delete<T>().Where(...).ExecuteAffrows();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 每个 SqlConnection GetFreeSql() 返回的 IFreeSql 实例相同;
|
||||||
|
- 可以对 fsql 设置 Aop 事件,比如监视 SQL;
|
||||||
|
- IFreeSql 自身的成员 IDbFirst、Transaction 不可用;
|
||||||
|
|
||||||
|
利用本功能可以快速将 FreeSql 使用到项目中,只需要处理好实体类的特性。
|
||||||
|
|
||||||
|
提示:FreeSql 兼容 EFCore 99% 的实体特性
|
||||||
Reference in New Issue
Block a user