Dapper with Multiple Records from Stored Procedure

ado.net c# dapper

Question

I have seen the answer to this question, How to map multiple records from a single SP with Dapper-dot-net, but it doesn't seem to work for my scenario.

Dummy Tables for illustration...

I have a SP that returns multiple record sets, and the first one looks like...

Column1 (int), Column2 (int)

and I have a class...

public class Columns
{
    public int Column1 { get; set; }
    public int Column2 { get; set; }
}

Then, I am trying to build a list of columns...

        using (var conn = new SqlConnection(...))
        {
            using (var multi = conn.QueryMultiple("SpData", 
                   commandType: CommandType.StoredProcedure))
            {
                var cols = multi.Read<Columns>().ToList();
            }
        }

When I call this, nothing seems to be populated in the cols variable, but I am not getting any errors. Also, if I break and look at what multi contains, I can see the data there. Can somebody see where I am going wrong?

Accepted Answer

I'm not sure whether to delete the question, or just add this as an answer as I spotted the obvious error (after I woke up)

I wasn't interested in the first two datasets from the SP, so I needed to skip by using Read...

multi.Read();//skip first recordset
multi.Read();//skip second recordset

It might help someone else, otherwise I will delete it soon.




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