您现在的位置是:网站首页> 编程资料编程资料
轻量级ORM框架Dapper应用之实现In操作_实用技巧_
2023-05-24
297人已围观
简介 轻量级ORM框架Dapper应用之实现In操作_实用技巧_
IN 操作符允许我们在 WHERE 子句中规定多个值。
本篇文章中,还是使用和上篇文章中同样的实体类和数据库,Dapper使用in操作符的代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using Dapper; using System.Data.SqlClient; using System.Data; using DapperApplicationByIn.Model; namespace DapperApplicationByIn { class Program { static void Main(string[] args) { // 定义连接字符串 string conn = ConfigurationManager.ConnectionStrings["AppConnection"].ConnectionString; #region in查询 using (IDbConnection connection = new SqlConnection(conn)) { var sql = "select * from Users where Email in @emails"; var result = connection.Query(sql, new { emails = new string[2] { "fqy@qq.com", "hyj@163.com" } }); result.AsList().ForEach(p => { Console.WriteLine("Id:"+p.UserId+" UserName:"+p.UserName+" Email:"+p.Email+" Address:"+p.Address); }); } #endregion Console.ReadKey(); } } } 程序运行结果:

示例代码下载地址:点此下载
到此这篇关于使用Dapper实现In操作的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 轻量级ORM框架Dapper应用之实现CURD操作_实用技巧_
- 轻量级ORM框架Dapper应用之安装Dapper_实用技巧_
- Entity Framework使用Code First模式管理事务_实用技巧_
- Entity Framework管理并发_实用技巧_
- Entity Framework使用Code First模式管理存储过程_实用技巧_
- Entity Framework使用Code First模式管理视图_实用技巧_
- Entity Framework加载控制Loading Entities_实用技巧_
- Entity Framework使用LINQ操作实体_实用技巧_
- Entity Framework使用Code First的实体继承模式_实用技巧_
- Entity Framework使用Code First模式管理数据库_实用技巧_
