diff --git a/Ado.md b/Ado.md new file mode 100644 index 0000000..556bd49 --- /dev/null +++ b/Ado.md @@ -0,0 +1,57 @@ +Ado 是 IFreeSql 下重要的对象之一,它包括所有对 SQL 操作的封装,类似 SqlHelper。 + +## 快速使用 + +1、查询 SQL 返回实体 + +```c# +//返回多条记录 +List list = fsql.Ado.Query("select * from t1"); + +//返回单条记录 +T item = fsql.Ado.QuerySingle("select * from t1 where id=@id", new { id = 1 }); + +//返回多个结果集 +var result = fsql.Ado.Query("select * from t1; select * from t2"); +List list1 = result.Item1; +List list2 = result.Item2; +``` + +Ado 下面所有参数 object parms 都可以接受匿名对象,或者字典: + +- new { id = 1, name = "xx" } +- new Dictionary\ { ["id"] = 1, ["name"] = "xx" } + +2、检测连接 + +```c# +bool isok = fsql.Ado.ExecuteConnectTest(); +``` + +3、SqlHelper + +fsql.Ado 还提供了 ExecuteReader、ExecuteDataSet、ExecuteDataTable、ExecuteNonQuery、ExecuteScalar 方法,使用起来等传统 SqlHelper 几乎一样。 + +--- + +4、CommandFluent + +fsql.Ado 重载方法太多的情况下,建议使用 CommandFluent,例如存储过程: + +```c# +DbParameter p2 = null; +fsql.Ado.CommandFluent("dbo.GetICMaxNum") + .CommandType(CommandType.StoredProcedure) + .CommandTimeout(60) + + .WithParameter("TableName", "tb1") + .WithParameter("FInterID", null, p => + { + p2 = p; //Output 参数 + p.DbType = DbType.Int32; + p.Direction = ParameterDirection.Output; + }) + .ExecuteNonQuery(); //提供 SqlHelper 的各种方式执行 + +Console.WriteLine(p2.Value); +``` \ No newline at end of file diff --git a/Home.md b/Home.md index 4fef7c7..be71e9c 100644 --- a/Home.md +++ b/Home.md @@ -56,4 +56,5 @@ FreeSql 除了支持基本的增删查改功能外,还支持基于现有数据 - [《优化之:延时加载》](%e5%bb%b6%e6%97%b6%e5%8a%a0%e8%bd%bd) - [《优化之:贪婪加载》](%e8%b4%aa%e5%a9%aa%e5%8a%a0%e8%bd%bd) - [《Expression 表达式函数》](%e8%a1%a8%e8%be%be%e5%bc%8f%e5%87%bd%e6%95%b0) +- [《Ado》](Ado) - [《AOP》](AOP) \ No newline at end of file diff --git a/_Sidebar.md b/_Sidebar.md index 0b38e16..c31dbab 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -39,6 +39,7 @@ * [自定义函数](%e8%a1%a8%e8%be%be%e5%bc%8f%e5%87%bd%e6%95%b0#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%A3%E6%9E%90) * [事务](%e4%ba%8b%e5%8a%a1) * [过滤器](%e8%bf%87%e6%bb%a4%e5%99%a8) +- [《Ado》](Ado) * [AOP✨](AOP) * [读写分离](%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb) * [分表分库](%e5%88%86%e8%a1%a8%e5%88%86%e5%ba%93)