BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

PetaPoco: Micro ORM For .NET

by Roopesh Shenoy on Jun 22, 2011 |

PetaPoco is a thin Object Relational Mapper (ORM) for .NET applications. Unlike full-fledged ORMs like NHibernate or Entity Framework, the emphasis is on simplicity of use and performance rather than richness of features. PetaPoco comes in a single C# file, works with strongly typed POCOs, supports class generation with T4 templates and more.

PetaPoco’s most interesting features are

  • Works with SQL Server, SQL Server CE, MySQL, PostgreSQL and Oracle databases
  • Helper methods for Insert/Delete/Update/Save and IsNew
  • Easy Transaction Support
  • Paged requests automatically work out total record count and fetch a specific page
  • Parameter replacement Support, can grab named parameters from object properties
  • Includes a low friction SQL Builder class
  • Partial Record Updates
  • Includes T4 Templates to generate POCO classes from database schema

All these features are explained in more detail along with samples in the PetaPoco website.

In terms of performance, PetaPoco is right up there with Dapper, only minimally slower than hand-coded DAL.

There are several tutorials that can help get started – series of blog posts on the official website as well as some independent posts. Besides, since it is open source, it is much easier to add conditions to handle specific scenarios like spatial data

Micro ORMs have started becoming popular, with many open source projects being released recently. Some of the other well known ones for .NET are Dapper and Massive. These are simpler and more efficient than full-fledged ORMs, often expecting the SQL statement to be hand-written rather than being generated completely dynamically. They also do not need verbose mapping files, that could become tedious to maintain and debug.  

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

No xml mapping files by Binoj Antony

Would have been nice if PetaPoco also supported Xml mapping files(xmldatamapper.codeplex.com/), I hate to specify the attributes in DTO or for that matter in any form of compiled code. Low coupling anyone..

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT