Dapper 也可以使用 数组参数

参考:Blog on Github

Dapper 调用存储过程 :单个参数
  static void Main(string[] args)
{
var connection = new SqlConnection("Data Source=.;Initial Catalog=Datamip;Integrated Security=True;MultipleActiveResultSets=True"); var info = connection.Query<Users>("sp_GetUsers", new { id = 5 },
commandType: CommandType.StoredProcedure);
}
Dapper 调用存储过程 :数组参数

需要使用 Sql Server 的自定义类型 : dbo.IDList

CREATE TYPE dbo.IDList
AS TABLE
(
ID INT
);
GO
c# code
  public static List<WorkLog> QueryWithTVP()
{
int[] idList = new int[] { 1, 2 };
var results = new List<WorkLog>();
try
{
var typeIdsParameter = new List<SqlDataRecord>();
// TypeID 数组参数对应的字段
var myMetaData = new SqlMetaData[] { new SqlMetaData("TypeID", SqlDbType.Int) };
foreach (var num in idList)
{
// Create a new record, i.e. row.
var record = new SqlDataRecord(myMetaData);
// Set the 1st colunm, i.e., position 0 with the correcponding value:
record.SetInt32(0, num);
// Add the new row to the table rows array:
typeIdsParameter.Add(record);
}
using (IDbConnection conn = new SqlConnection(DBConfig.ConnectionString))
{
conn.Open();
//调用存储过程,IDList: 自定义类型
results = conn.Query<WorkLog>("dbo.GetWorkLog_ByTypeIds",
new TableValueParameter("@TypeIds", "IDList", typeIdsParameter)
, commandType: CommandType.StoredProcedure).ToList();
}
}
catch (Exception)
{ throw;
} return results;
}

Dapper use Table Value Parameter in C# (Sql Server 数组参数)的更多相关文章

  1. Sql Server 带参数的存储过程执行方法

    Sql Server 带参数的存储过程执行方法 Visual C# 动态操作 SQL Server 数据库实例教程(4):带参数的存储过程执行方法 上一篇文章介绍了带参数的SQL语句执行方法和不带参数 ...

  2. sql server exec 参数的传递

    来源:https://www.cnblogs.com/guohu/p/11142991.html 1 :普通SQL语句可以用exec执行 Select * from tableName exec('s ...

  3. How to Remove Table Partitioning in SQL Server

    In this article we will see how we can remove partitions from a table in a database in SQL server. I ...

  4. Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...

  5. 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...

  6. Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]

    http://sqlserverbuilds.blogspot.jp/   What version of SQL Server do I have? This unofficial build ch ...

  7. Microsoft SQL Server Version List(SQL Server 版本)

    原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Servic ...

  8. SQL Server 存储中间结果集

    在SQL Server中执行查询时,有一些操作会产生中间结果集,例如:排序操作,Hash Join和Hash Aggregate操作产生的Hash Table,游标等,SQL Server查询优化器使 ...

  9. (转)SQL Server 性能调优(cpu)

    摘自:http://www.cnblogs.com/Amaranthus/archive/2012/03/07/2383551.html 研究cpu压力工具 perfom SQL跟踪 性能视图 cpu ...

随机推荐

  1. Servlet 4.0 入门

    Java™ Servlet API 是主流服务器端 Java 的基本构建块,也是 Java EE 技术的一部分,例如,用于 Web 服务的 JAX - RS.JSF (JavaServer Faces ...

  2. 依赖注入(DI)与控制反转(IOC)基础知识

    依赖注入(DI)与控制反转(IOC)基础知识 一.什么是依赖注入? 依赖注入英文是Dependcy Injection简写DI,依赖注入会将所依赖的对象自动交由目标对象使用,而不是让对象自己去获取. ...

  3. TRex,一个基于DPDK的数据包发生器,测试仪

    1. introduction TRex是cisco基于Intel dpdk开发的软件程序.推荐在CentOS/RHEL 7.6, 64bits中运行,否则connectx-4网卡不可使用. 笔者在U ...

  4. 手机上的unity路径

    转载自:https://www.xuanyusong.com/archives/2656 Application.dataPath路径在PC上无论是Editor还是运行时毫无压力非常万能,但是在手机上 ...

  5. 企业SDLC建设不成熟设想

    一.说明 1.1 背景说明 之前在N市,面试的是“IT系统安全工程师”的岗位但合同上签的是“集成工程师”的名头(前阵子找之前的邮件offer才注意到的),工作内容现在看来还是和当时离职时表述一样基本一 ...

  6. JMeter一台机器可以支持多大的并发量

    Support for concurrent thread is basically depends on many factors like OS, free RAM and connections ...

  7. ElasticSearch 线程池类型分析之 ExecutorScalingQueue

    ElasticSearch 线程池类型分析之 ExecutorScalingQueue 在ElasticSearch 线程池类型分析之SizeBlockingQueue这篇文章中分析了ES的fixed ...

  8. Go学习笔记之Map

    Go学习笔记之Map Map 引用类型,哈希表.map的key必须可以比较相等,除了slice, map, function的内建类型都可以作为key.struct类型不包含上述字段,也可作为key. ...

  9. sqlserver获得数据库非聚集索引的代码

    创建Index DECLARE @zindex_sql NVARCHAR(max); SET @zindex_sql = N''; SELECT @zindex_sql = @zindex_sql + ...

  10. .net core将URL请求格式化为XML或JSON(网站动态生成sitemap.xml)

    .net core将URL请求格式化为XML或JSON(网站动态生成sitemap.xml) 首先设置 Startup.cs 文件 配置 ConfigureServices services .Add ...