Dapper Multi-mapping APIs splitOn param Error - I'm not using MultiMapping

.net c# dapper sql

Question

I have a project where I interact with many stored procs. There is no bare SQL Selects. I am using Dapper. We are not trying to use any of the MultiMapping features. I am trying to figure out why this one proc would return that error? What should I check? What should I look for?

Error: When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id\r\nParameter name: splitOn

Accepted Answer

You should use Execute() instead of Query(), as your SP does not return any record. Dapper assumes you are trying to get data, so maps the missing results to your model class.


Popular Answer

I ran into this problem today, and couldn't understand why I was getting the MultiMapping error message when I wasn't actually trying to multi-map in the first place. My code uses dapper's Query instead of Execute, because the sproc does actually return some rows.

Turns out that in my stored procedure, which takes a single varchar param, if the param is passed as NULL, then the result is just return value integer 0. If its passed as an empty string, I get an empty result set on top of the normal return value 0.

Because I had told Dapper to use Query<MyClass>, it looked at the plain 0 return from the null version as an int, not a MyClass, and tried to Multimap, which is where that multimap error comes from.

To fix this, I changed my stored procedure to convert a null param into an empty string param, thus ensuring an empty result set instead of no result set, and then Dapper started happy working again.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why