yysun's space

Dragon: Another Micro-ORM Tool

Posted on: January 19, 2012

Introduction

Dragon is a simplified ORM tool. It has similar syntax to Matrix.Data.Database, but maps to static types not dynamic. E.g.

Database database = Database.Open("Users");
var users = database.Query<TestUser>("select UserId, Email from UserProfile where UserId=@UserId", new { UserId = 2 }).ToList();
Assert.AreEqual(2, users[0].UserId);
Assert.AreEqual("user@company.com", users[0].Email);

Database Methods

The Database Class has methods Open, Execute QueryValue and Query.

  • Open, opens database connection, the parameter can be a connection string, or a connection string name in app.config file or a registry path to a connection string.
  • Execute, creates a command and runs ExecuteNonQuery.
  • QueryValue, creates a command and runs ExecuteScalar.
  • Query, creates a command with SQL statement(s) or stored procedure name and creates objects. The Query method supports up to 3 multiple record sets. The result objects are returned in a Tuple, E.g.

Database database = Database.Open("Users");
var users = database.Query<TestUser, TestMemberShip, TestUserRole>(
    @"select * from dbo.UserProfile
        select * from dbo.webpages_Membership
        select * from dbo.webpages_Roles");

Assert.AreEqual(1, users.Item1.ToList()[0].UserId);
Assert.AreEqual(0, users.Item2.Count());
Assert.AreEqual("Sysadmin", users.Item3.ToList()[0].RoleName);

Source Code

https://github.com/yysun/Dragon

Advertisements

1 Response to "Dragon: Another Micro-ORM Tool"

A valiant and commendable effort. Your use of Tuple is a little weird but it offers a feature that most other microORMs don’t. Your use of a static Guard class is something I haven’t seen before. I do like how you are mapping to staticly typed objects, which is a big plus, but what I still can’t get over with all of these microORMs is all the “magic strings”. If you can come up with a Linq-like DSL and implement static reflection so that developers could use lambda syntax to specify the column names, then you’d be on the right track to creating a popular microORM that would appease all the statically typed, no “magic strings” here kind of people.

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


  • None
  • Pk: The horizontal view is a pleasure to use! Good thinking
  • randyburden: A valiant and commendable effort. Your use of Tuple is a little weird but it offers a feature that most other microORMs don't. Your use of a static Gu
  • reav: great work done on Rabbit Framework. just started to learning it, and by now i think it will solve all my problems and questions, that i had in webpag

Categories

%d bloggers like this: