码迷,mamicode.com
首页 > 移动开发 > 详细

Send SqlParameter to Dapper

时间:2016-07-31 13:09:26      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:

Question:

I‘ using Dapper in my project. I have a list of SqlParameters and I want to send it to Dapper. But Dapper needs an object (name, value). How can I convert a SqlParameter to an object. I know this doesn‘t work:

conn.Query<TModel>(sql, parameters.Select(p => new {p.ParameterName=p.Value}))

any suggestions?

Answer:

Stumbled across this looking for something else - but can offer some insight that may help others in the future.

You can use the Dapper.DynamicParameters object to add items that can be legally passed to Dapper Queries, i.e. (hand-coded)

var args = new DynamicParameters(new {});
parameters.ForEach(p => args.Add(p.ParameterName, p.Value));
conn.Query<TModel>(sql, args );

from url:http://stackoverflow.com/questions/22978754/send-sqlparameter-to-dapper

 

Send SqlParameter to Dapper

标签:

原文地址:http://www.cnblogs.com/wangqiideal/p/5722745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!