Dapper processing returns an empty result set

We use Dapper to display our sql data, and so far it has worked very well. I have a case, although we are doing something similar to:

someObject = con.Query<T>("GetInfoSproc", p, commandType: CommandType.StoredProcedure).Single(); 

This works fine as long as the stored procedure I call returns the data. There are times when a stored procedure may not return a result and return an error in the out parameter. This seems to be causing the problem in Dapper because dapper throws an error:

"When using the multiple display APIs, make sure you set the splitOn parameter if you have keys other than Id."

Is there a way to write a query so that it can correctly handle the case when an empty result is returned or is this a Dapper constraint?

+6
source share
1 answer

SingleOrDefault() is your friend here

Try the following:

 someObject = con.Query<T>("GetInfoSproc", p, commandType: CommandType.StoredProcedure).SingleOrDefault(); if (someObject != null) { // operate on your results here } return someObject; 

also you need to make sure that T is Nullable

+1
source

Source: https://habr.com/ru/post/893886/


All Articles