Dapper
2015-12-11 14:13
465 查看
本文内容摘自dapper官网 动态类型 public static IEnumerable<dynamic> Query (this IDbConnection cnn, string sql, object param = null, SqlTransaction transaction = null, bool buffered = true)
This method will execute SQL and return a dynamic list.
Example usage:
var rows = connection.Query("select 1 A, 2 B union all select 3, 4"); ((int)rows[0].A) .IsEqualTo(1); ((int)rows[0].B) .IsEqualTo(2); ((int)rows[1].A) .IsEqualTo(3); ((int)rows[1].B) .IsEqualTo(4); 多次执行语句
Execute a Command multiple times
The same signature also allows you to conveniently and efficiently execute a command multiple times (for example to bulk-load data)Example usage:
connection.Execute(@"insert MyTable(colA, colB) values (@a, @b)", new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } } ).IsEqualTo(3); // 3 rows inserted: "1,1", "2,2" and "3,3"
This works for any parameter that implements IEnumerable for some T.
集合 支持
List Support
Dapper allow you to pass in IEnumerable and will automatically parameterize your query.For example:
connection.Query<int>("select * from (select 1 as Id union all select 2 union all select 3) as X where Id in @Ids", new { Ids = new int[] { 1, 2, 3 });
Will be translated to:
select * from (select 1 as Id union all select 2 union all select 3) as X where Id in (@Ids1, @Ids2, @Ids3)" // @Ids1 = 1 , @Ids2 = 2 , @Ids2 = 3
一次执行多条语句
Multiple Results
Dapper allows you to process multiple result grids in a single query.Example:
var sql = @" select * from Customers where CustomerId = @id select * from Orders where CustomerId = @id select * from Returns where CustomerId = @id"; using (var multi = connection.QueryMultiple(sql, new {id=selectedId})) { var customer = multi.Read<Customer>().Single(); var orders = multi.Read<Order>().ToList(); var returns = multi.Read<Return>().ToList(); ... }
Stored Procedures 存储过程
相关文章推荐
- Android自动填充短信验证码
- Android 事件分发机制
- 游戏应用快速审核上架
- 在android中使用高德地图进行定位
- Android之日期/时间选择对话框
- Android之项目推荐使用的第三方库
- android4.4系统源码编译(三)_编译
- Missing type map configuration or unsupported mapping解决方法
- Android SQLite 增,删,改,查
- 跳转app评分
- Android学习之Service生命周期及其通信
- 牛郎织女做法解释android activity生命周期
- zhphp framework(十六) Appcontroller
- 年末重磅 | 12月Unity 2D新功能发布会现已开放报名!
- Android中TableLayout中的布局
- Android官方培训课程中文版(v0.9.4)
- java,android编程框架
- Android 笔记
- 【开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位网友补充完善
- dapper.net for mysql