PetaPoco - A couple of little tweaks
Friday, 8 April 2011
I've been getting some great feedback on PetaPoco, all very positive. There's also been some great suggestions including these little tweaks...
This post is about PetaPoco - "a tiny ORMish thing for your POCOs". Read more on the PetaPoco Project Page.
These changes are in response to some great suggestions by Chris Marisic (@dotnetchris). Thanks Chris.
In order to make the Sql builder a little more "fluenty", I've added a new static
Builder property to the
Sql class that simply returns a new instance of the
Sql class. So now, instead of this:
new Sql().Append("SELECT * FROM whatever");
Sql.Builder.Append("SELECT * FROM _whatever");
It's an almost trivial change, but it now reads better.
Auto Select Clause Improvement
Previously PetaPoco could automatically convert this:
var a = db.SingleOrDefault<article>("WHERE id=@0", 123);
var a = db.SingleOrDefault<article>("SELECT col1, col2, col3 FROM articles WHERE id=@0", 123);
But now it will also handle this:
var a = db.SingleOrDefault<article>("FROM whatever WHERE id=@0", 123);
In otherwords if it sees a statement that starts with
FROM, it puts in just the
SELECT and column list and not the
T4 Template Improvements
It seems there's a weird quirk with NuGet where it installs files in reverse alphabetical order. This resulted in the T4 template getting installed before the required include files and therefore a bunch of errors ensued.
Record.tt has now been renamed to
Database.tt as per David Ebbo's suggestion. Thanks David.
While I was at it, I also made some template improvements to make it work a bit more automatically and to give better feedback if something goes wrong. Now, if you have a valid connection string in your project and you install PetaPoco with NuGet, you should automatically get everything generated - and if not, a
Database.cs file with an appropriate error message.
As always, this is all available in GitHub and NuGet now.
Leave a comment