少年恃险若平地,独倚长剑凌清秋。这篇文章主要讲述轻量级ORM框架 第二篇:Dapper相关的知识,希望能为你提供帮助。
1. in操作
IDbConnection connection = new SqlConnection("Data Source=.; Initial Catalog=DapperTest; Integrated Security=True; MultipleActiveResultSets=True"); var sql = "select * from Users where Email in @emails"; var info = connection.Query< Users> (sql, new { emails = new string[2] { "1QQ", "7QQ" } });
文章图片
2. 多条sql执行
IDbConnection connection = new SqlConnection("Data Source=.; Initial Catalog=DapperTest; Integrated Security=True; MultipleActiveResultSets=True"); var sql = "select * from Product; select * from Users"; var multiReader = connection.QueryMultiple(sql); var productList = multiReader.Read< Product> (); var userList = multiReader.Read< Users> (); multiReader.Dispose();
【轻量级ORM框架 第二篇(Dapper)】3.多表join操作
var sql = @"selectp.ProductName,p.CreateTime,u.UserName from Product as p join Users as u on p.UserID = u.UserID where p.CreateTime > \'2019-1-1\'; "; var result = connection.Query< Product, Users,Product> (sql, (product, users) => { product.UsersOwner = users; return product; },splitOn:"UserName");
文章图片
4.支持存储过程
use DapperTest set ansI_nulls on go set quoted_identifier on go create proc [dbo].[sp_GetUsers] @id int as begin select * from Users where UserID = @id ; end
var info = connection.Query< Users> ("sp_GetUsers", new { id = 10 }, commandType: CommandType.StoredProcedure);
文章图片
推荐阅读
- c#中退出WinForm程序包括有很多方法,如:this.Close(); Application.Exit();Application.ExitThread(); System.Environmen
- Android刷量
- android课程表控件悬浮窗Todo应用MVP框架Kotlin完整项目源码
- 搭建qt for android遇到的问题
- 已删除的部件(部件/xl/vbaProject.bin。(Visual Basic for Applications(VBA)))
- vue2.0在android5.0白屏, es6转es5保证浏览器兼容性
- virtualenvwrappers 踩坑
- Application Security Per-Engagement
- cordova build android Command failed with exit code EACCES