Is there any way to use Dapper.NET with stored procs that return multiple result sets?
In my case, the first result set is a single row with a single column; if it's 0
then the call was successful, and the second result set will contain that actual rows/columns of data. (and if it was non-zero, an error occured and no second result set will be provided)
Any chance to handle this with Dapper.NET? So far, I'm only ever getting back that single 0
- but nothing more.
Update: OK, it works fine - as long as the result set no. 2 is a single entity:
Dapper.SqlMapper.GridReader reader =
_conn.QueryMultiple("sprocname", dynParams,
commandType: CommandType.StoredProcedure);
int status = reader.Read<int>().FirstOrDefault();
MyEntityType resultObj = reader.Read<MyEntityType>().FirstOrDefault();
Now, I have yet another requirement.
Dapper's multi-mapping (splitting up a single row returned from SQL Server into two separate entities) for that second result set doesn't seem to be supported as of yet (at least there doesn't seem to be an overload of .Read<T>
that can handle multi-mapping).
How can I get split that row into two entities?
4条答案
按热度按时间ao218c7q1#
QueryMultiple
supports the ability to deal with multiple result sets. The only design restriction we added was totally disabling buffering for the grid reader. This means the whole API is streaming.In the simplest case you can use:
In the slightly more sophisticated case you can do crazy stuff like this:
You'll need to add this using statement to enable QueryMultiple .
pcrecxhr2#
Have you tried the
QueryMultiple
method? It says it should:Execute a command that returns multiple result sets, and access each in turn
You'll need to add this using statement to enable QueryMultiple .
368yc8dk3#
Multiple result set.
You'll need to add this using statement to enable QueryMultiple .
Stored procedure:
nle07wnf4#
For me, it was missing one column in my DB table, one of my query is getting exception in
QueryMulitpleAsync()
due to that missing column.I will suggest that find the one that blocking you, then compare DB column and your raw query string.