Friday, 15 August 2014

PetaPoco .Net light weight ORM

Last night I was having discussion on Asp.net MVC4 with my friend from Morocco who is new in Asp.net MVC and I got introduced with PetaPoco ( i.e. ORM kind of thing for .net ), my friend was using PetaPoco to map database entities to models. Later on I got little R&D on it and found it amazing as this is just a single file with 1500 lines of code and giving us following top features we usually used to be interested in :

  • Tiny, no dependencies... a single C# file you can easily add to any project.
  • Works with strictly undecorated POCOs, or attributed almost-POCOs.
  • Helper methods for Insert/Delete/Update/Save and IsNew
  • Paged requests automatically work out total record count and fetch a specific page.
  • Easy transaction support.
  • Better parameter replacement support, including grabbing named parameters from object properties.
  • Great performance by eliminating Linq and fast property assignment with DynamicMethod generation.
  • Includes T4 templates to automatically generate POCO classes for you.
  • The query language is SQL... no weird fluent or Linq syntaxes (yes, matter of opinion)
  • Includes a low friction SQL builder class that makes writing inline SQLmucheasier.
  • Hooks for logging exceptions, installing value converters and mapping columns to properties without attributes.
  • Works with SQL Server, SQL Server CE, MySQL, PostgreSQL and Oracle.
  • Works under .NET 3.5 or Mono 2.6 and later.
  • Experimental support for dynamic under .NET 4.0 and Mono 2.8
  • NUnit unit tests.
  • OpenSource (Apache License)
  • All of this in about 1,500 lines of code



PetaPoco can be downloaded from following sources :

  • NuGet -http://nuget.org/List/Packages/PetaPoco
  • GitHub -https://github.com/toptensoftware/petapoco

More detail's can be found on their official site : http://www.toptensoftware.com/

Whats next :
Console based .Net project with basic crud operation using PetaPoco.

Till then stay tuned and enjoy codding :)