Dapper use Table Value Parameter in C# (Sql Server 数组参数)
Dapper 也可以使用 数组参数
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 数组参数)的更多相关文章
- Sql Server 带参数的存储过程执行方法
Sql Server 带参数的存储过程执行方法 Visual C# 动态操作 SQL Server 数据库实例教程(4):带参数的存储过程执行方法 上一篇文章介绍了带参数的SQL语句执行方法和不带参数 ...
- sql server exec 参数的传递
来源:https://www.cnblogs.com/guohu/p/11142991.html 1 :普通SQL语句可以用exec执行 Select * from tableName exec('s ...
- 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 ...
- Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...
- 转: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 ...
- 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 ...
- 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 ...
- SQL Server 存储中间结果集
在SQL Server中执行查询时,有一些操作会产生中间结果集,例如:排序操作,Hash Join和Hash Aggregate操作产生的Hash Table,游标等,SQL Server查询优化器使 ...
- (转)SQL Server 性能调优(cpu)
摘自:http://www.cnblogs.com/Amaranthus/archive/2012/03/07/2383551.html 研究cpu压力工具 perfom SQL跟踪 性能视图 cpu ...
随机推荐
- json for modern c++(nlohmann json)使用小计
前言 一开始使用jsoncpp,但是jsoncpp已经不更新了,nlohmann还在更新,并且jsoncpp做过一次大的版本升级,导致api不兼容,以前使用过的工程代码不能很好的升级到新的版本,并且j ...
- 2018-2019-2 网络对抗技术 20165318 Exp 9 Web安全基础
2018-2019-2 网络对抗技术 20165318 Exp 9 Web安全基础 基础问题回答 实践过程记录 WebGoat安装 SQL注入攻击 1.命令注入(Command Injection) ...
- 【转】调用百度API,HTML在线文字转语音播报
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 模型区分度衡量指标-KS值
1.KS值--学习器将正例和反例分开的能力,确定最好的“截断点” KS曲线和ROC曲线都用到了TPR,FPR.KS曲线是把TPR和FPR都作为纵坐标,而样本数作为横坐标.但是AUC只评价了模型的整体训 ...
- cad问题小百科 持续更新
一些浩辰的问题移步去: 浩辰问题 (浩辰可能和桌子具有相同的问题,所以这篇你可能还是要看 cad2007遇到了这种情况 安装问题安装CAD出现C++2005问题的解决方法,出现此问题,原 ...
- FTP服务器安装测试
FTP服务器基本搭建 -- vsftpd 作用:文件的基本上传和下载 1.服务器端 软件的安装: $ sudo apt-get install vsftpd (1)修改配置文件 $ sudo vim ...
- [原创]K8tools 20191111/K8工具合集
K8tools 20191111 声明: 工具仅供安全研究或授权渗透,非法用途后果自负. 下载: https://github.com/k8gege/K8tools PS: 不定期更新,文件比较大,可 ...
- [转帖]JVM性能调优详解
JVM性能调优详解 https://www.cnblogs.com/secbro/p/11833651.html 应该是 jdk8 以前的方法 貌似permsize 已经放弃这一块了. 前面我们学习了 ...
- idea(2018.3.5)破解
第一步:下载idea,https://www.jetbrains.com/idea/download/#section=windows,双击进行安装 第二步:下载破解的jar包:链接:https:// ...
- java小程序---简陋版多人聊天室
功能需求: 1 每运行一次主函数,创建一个客户端聊天界面; 2 客户端界面分三块,公屏(显示所有客户端发送的信息),私屏(用于输入个人想要发送的信息),发送按钮(点击一次,将客户端信息发送到服务端) ...