-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dapper - reader.IsConsumed is false even after reading the last resultset #469
Comments
Can I assume this ties into I will try to repro. Do you have a short but complete example I can use to
|
Yes, Below is the sample code I am using to execute the stored procedure, using (var results = await DbContext.Database.Connection.QueryMultipleAsync("StoredProcedure", parameters, commandType: CommandType.StoredProcedure))
{
IEnumerable<POCO1> collection1 = await results.ReadAsync<POCO1>();
IEnumerable<POCO2> collection2 = results.Read<POCO2, Class1, Class2,POCO2>
(
(obj, obj1, obj2)
{
obj.Prop1 = obj1;
obj.Prop2 = obj2;
}, "Col1, Col2");
//results.IsConsumed is set to false when the procedure returns only two sets.
if (!results.IsConsumed)
{
IEnumerable <POCO3> collection3 = await results.ReadAsync<POCO3>();
}
} |
Just looking at the code: try adding .ToList() to the end of each of those Note: for async, the pattern is: var foo = (await someMethod(...)).ToList() Meaning: you await before you ToList
|
Thanks, I updated the code and converted that to a list |
And... did that fix it? Or does the problem still occur with the ToList()
|
The issue still occurs with ToList() |
OK. I'll have a look and see if I can get a repro from your code
|
Hi all,
In digging through the source I think the issue comes in the SqlMapper.GridReader.cs in the NextResult() function. I'm thinking in the else statement, right after the Dispose() is called, the IsConsumed could be set to true. Or even put the IsConsumed = true in the Dispose() function. Thoughts? |
Another place where IsConsumed is never set, |
I am using Dapper version 1.42.0 and SQL Server as the back end to read multiple result-set by executing a Stored Procedure. The issue is that the IsConsumed property of the reader object is false when the last result-set uses spiltOn option to create multiple objects.
This isn't an issue most of the time as this occurs on the result-set, but in my case I have three result sets in which the last set is optional and the 2nd set uses splitOn option to create multiple objects. I use the reader.IsConsumed to determine whether to Read the last result-set or not and in cases when the stored procedure returns only 2 sets I receive an ObjectDisposed error when the code proceeds to read the 3rd set
The text was updated successfully, but these errors were encountered: