Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dapper - like operator using DynamicParameters

Tags:

c#

.net

dapper

This works:

var list = conn.Query<int>(
  "select Id from Person where Id in @ids", 
  new { ids = new int[] { 1, 2, 3 } }
);

This throws "No mapping exists from object type System.Int32[] to a known managed provider native type.":

DynamicParameters parameters = new DynamicParameters(
  new { ids = new int[] { 1, 2, 3 } }
);
var list2 = conn.Query<int>(
  "select Id from Person where Id in @ids", 
  parameters
);

Any ideas?

like image 771
Trev Avatar asked Jul 15 '11 17:07

Trev


People also ask

What is DynamicParameters in dapper?

Dapper also provides a DynamicParameters class, which represents a "bag" of parameter values. You can pass an object to its constructor. Suitable objects include a Dictionary<string, object> : var dictionary = new Dictionary<string, object>

Does SqlKata use Dapper?

SqlKata provide an easy way to execute your queries, by using the famous package Dapper.

What is DynamicParameters?

Dynamic parameters allow you to create actions that are different every time they are performed. Dynamic parameters can be passed as arguments to most vizact actions. The value of these parameters is determined when the action is performed, and you can setup these parameters to change values every time.


1 Answers

Just fixed this issue in the latest dapper (grab from hg), the code used to diverge around the DynamicParameters value extraction. Now the code being run is the same.

like image 68
Sam Saffron Avatar answered Sep 22 '22 14:09

Sam Saffron