Dapper return result fails after enumeration

dapper

Question

I have a dapper query multiple function that outputs a number of different lists except for the very first list. While debugging I discovered that when the code gets to the following line in Dapper the results disappear:

public IEnumerable<T> Read<T>....
    var result = ReadDeferred<T>(gridIndex, deserializer.Func, typedIdentity); //result has correct db values here
    return buffered ? result.ToList() : result; //result = Enumeration yielded no results

The ReadDeferred function does not process any code in the try or finally clause. Why is the value of result being lost in enumeration?

Here is my code that calls dapper:

var results = con.QueryMultiple("GetInspections", p, commandType: CommandType.StoredProcedure, commandTimeout: 5000);
var inspectionDetails = new Inspection
{
    InspectionDetailList = results.Read<Inspection>().ToList(), <-- this one does not popuplate
    SOHList = results.Read<SOHPrograms>().ToList(),
    BuildingList = results.Read<Building>().ToList(),
    AdministratorList = results.Read<Employee>().ToList(),
    NotAdminList = results.Read<Employee>().ToList(),
    InspectionList = results.Read<InspectionList>().ToList()
};

return inspectionDetails;

I have verified that there are result sets being returned for each list from the sql query.

Popular Answer

This problem had a two part answer, because I had two problem errors. The first was that I was calling the InspectionDetailList as a list from inside the Inspection object which I removed and the second was to change the code that calls dapper to use a using statement and call the pieces individually. Thanks goes to a friend and one of the overflow posts found here.

using(var results = con.QueryMultiple("GetInspections", p, commandType: CommandType.StoredProcedure, commandTimeout: 5000))
{
    var inspectionDetails = results.Read<Inspection>().First();
    inspectionDetails.OshList = results.Read<SOHPrograms>.ToList();
    inspectionDetails.BuildingList = results.Read<Building>.ToList(); 
}



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