PetaPoco – Multiple Result Sets

The other day I got enough time to put the ability to fetch multiple result sets into PetaPoco. Its relatively simple to use and works like this.

Given these two classes with corresponding tables:

    public class Table1
    {
        public string Name { get; set; }
    }
    public class Table2
    {
        public string Col1 { get; set; }
        public int Col2 { get; set; }  
    }

Both results can be retrieved in one call to the database like so:

    var result = db.FetchMultiple<Table1, Table2>(
        "select name from table1;" +                                      "select col1,col2 from table2");

    var table1list = result.Item1;  //List<Table1>
    var table2list = result.Item2;  //List<Table2>

where result here is a Tuple<List<Table1>, List<Table2>>.

Here the semi-colon represents the separation of the two queries. This is the MS SQL server syntax so please check your database specific syntax to use multiple result sets.

If you don’t like returning a Tuple from this query you can provide your own callback to the FetchMultiple method. The callback for the above query would be of type. Func<List<Table1>, List<Table2>, ReturnClass>

The feature is currently only available in my master branch where you can find the download package here https://github.com/schotime/PetaPoco/downloads or directly https://github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.5.zip.

Hope you find it useful.

Advertisements
This entry was posted in .NET and tagged , . Bookmark the permalink.

One Response to PetaPoco – Multiple Result Sets

  1. Eduardo says:

    I’m not sure if I get the point on this one, but good to know it can be done. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s