I am trying to have dapper return List<KeyValuePair<int, dynamic>>
I have made what I believe to be the absolute simplest possible query to illustrate the issue:
using (SqlConnection conn = new SqlConnection(_connectionString))
{
return conn.Query<int, string, bool, KeyValuePair<int, dynamic>>("SELECT 1 AS 'SomeInt', 'A' AS 'SomeString', 'True' AS 'SomeBool'", (i, s, b) =>
new KeyValuePair<int, dynamic>(
i,
new
{
TheString = s,
TheBool = b
}
), splitOn: "SomeString").AsList();
}
When I try to run this I get System.ArgumentException: 'When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id.
I think that I am specifying the splitOn parameter correctly as SomeString ... ?
I have looked at a number of other SO questions regarding this error including Dapper Multi-mapping Issue, When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", "splitOn, and Correct use of Multimapping in Dapper, and if the answer is in one of those I can't find it.
I specifically tried to mirror what the answer here Correct use of Multimapping in Dapper, but it doesn't work for me.
I did notice that in the vast majority of other examples, the code looks like conn.Query<x, y, x> (i.e. the return value is listed as the first value as well). I'm not sure if this matters or not, or even if I'm able to do what I want. I'm pretty new to Dapper.
Thank you in advance!
List<KeyValuePair<int, Tuple<string, bool>>>, but I want to name the string and the bool, notitem1anditem2. I am aware that I could create a class with a string and a bool and have dapper map to that class, but this is the only place in the whole code base where I would reference that class, so it seems ... excessive I guess. (This is in an API, so after I execute the query I send the results as JSON to a front-end website, and I don't want the front-end to have to deal withitem1anditem2.) - Brian