I have a simple query with multiple parameters and one of them is an IN parameter, ie:
select d.TitleName
from dbo.Device d
where d.Id in @ids
and d.Disabled = @isDisabled
I need to build these parameters dynamically so I cannot do this:
var model = await conn.QueryAsync<DeviceMaintenanceTableModel>(myQuery, new { ids, isDisabled });
I tried passing in a dynamic parameter object from an IDictionary<string, object>
class and got an error:
var ids = new[] { 4456, 22686 };
var p = new Dictionary<string, object>();
p.Add("@ids", ids);
var dp = new DynamicParameters(p);
var model = await conn.QueryAsync<DeviceMaintenanceTableModel>(myQuery, dp);
Error:
No mapping exists from object type Newtonsoft.Json.Linq.JValue to a known managed provider native type.
I ended up just doing string.Join
and passing it in as a string parameter type, but I was wondering if there is a way to use Dapper's WhereIn
clause parameter with the DynamicParameters
class?