Schotime @ November 20, 2011
.NET
|
Comments (1)
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.
Schotime @ August 21, 2011
.NET
|
Comments (1)
PetaPoco is a great way to map results from a database. Usually these are flat objects, however sometimes its useful to map many-to-one/one-to-many relationship directly into a viewmodel or complex object. This feature has been possible in PetaPoco since version 4 as shown in the blog post by Brad, (http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships) however, custom mapping needed to [...]
Schotime @ May 31, 2011
.NET
|
Comments (5)
A couple of weeks ago I showed how we can use the awesome Glimpse project with PetaPoco to show all the SQL’s processed in the current request. The problem was there was a few things that needed to make it into both PetaPoco and Glimpse to support this. The PetaPoco changes were in place as [...]
Schotime @ May 16, 2011
.NET
|
Comments (5)
Update 20/Nov/2011: This has been now added to my master branch and is available here for download as of 4.0.3.5. https://github.com/schotime/PetaPoco/downloads The other day I set out to build another way to configure the mappings for PetaPoco. Here is how you currently configure a mapping using attributes. [TableName("AttribPocos")] [PrimaryKey("Id")] public class attribpoco { public int [...]
Schotime @ May 10, 2011
.NET
|
Comments (5)
Last weekend I created a Glimpse plugin for PetaPoco. It was surprisingly easy. In this post I’ll show you how to create your own. Please note as Glimpse is still in Beta, this example may change. but I will endeavour to update the post when and if the interface changes. This plugin is based on [...]
Schotime @ May 9, 2011
.NET
|
Comments (1)
Last week I blogged about upcoming performance statistics that enable you to see all the Sql’s that were executed by PetaPoco in the current request. It was also just over a week ago that I learned about Glimpse from this Mix video by Scott Hanselman. And wow what an impact. Anthony van der Hoorn (@anthony_vdh) [...]
Schotime @ May 4, 2011
.NET
|
Comments (6)
As I mentioned a few posts ago, in the last couple of years I moved away from writing native SQL to a full blown ORM and back again. Well not all the way back. Here is where PetaPoco comes in. I had been using my own SQL to Object mapper for a while before I [...]
Schotime @ May 3, 2011
.NET
|
Comments (1)
The other day Sam from stackoverflow blogged about a slow page caused by a combination of problems resulting in them using Dapper to map native SQL to the objects resulting in a nice performance improvement. I liked how he made the queries executed for the current request display in html comments in the html source, [...]
Schotime @ May 2, 2011
.NET
|
Comments (3)
Today I was presented with a problem when binding click events to action icons. You know the scenario; you have a table with a list of data and one of the columns has icons/links like “edit”, “new”, “view”, “delete” etc. This is how I’m using the jQuery to bind the click event to the links [...]
Schotime @ May 1, 2011
.NET
|
Comments (1)
I’ve always used native SQL for my applications. Approximately a year or so ago I finally decided to give NHibernate a look and see what all the hype was about. I gave it a test run on a new project as there is really nothing like real world requirements to show you what a tool [...]