Home Software Blog Wallpapers Webtools
CursiveDB - An ADO.NET wrapper

Software listSoftware List

Delicious Bookmark this on Delicious

CursiveDB - An ADO.NET wrapper

zip file Download file (170 KB) [Downloaded 357 times]


CursiveDB is an ADO.NET wrapper library which encourages a fluent-style of programming. Apart from having a number of shortcut methods for creating and executing raw SQL queries and stored procedures, it's also got built-in support for retries, a light-weight Database to Object mapper and also a SQL script runner.

Almost all CursiveDB methods are implemented as extension methods of the ADO.NET Connection and Command classes. This ensures that CursiveDB does not get in the way of using standard ADO.NET classes.

In-built support for retries

Automatic retries of failed database connections. You can use retries using the retry callbacks which are available while opening a database connection.

SqlConnection c = new SqlConnection();
int retryCount = 0;
    .If((e, source) =>
        if (e is InvalidOperationException) 
            return false; // stop retrying
            return true; // do a retry
catch(Exception ex)
    Console.WriteLine("None of the retries succeeded! This is the final exception!");
Retries for failed database commands

You can specify retry callbacks which are executed when data base command fails. These handlers are available in all most all methods which interact with a database.

SqlCommand cmd = new SqlCommand("select * from authors");
    .MaximumTimes(3)  /* retry 3 times */
    .WithWaitOf(1000) /* wait for 1 sec between retries */
Fluent style ADO.NET productivity methods.

CursiveDB methods make programming ADO.NET very simple. Methods are easy to use and provided via extension methods so you don't need to use any 'new' classes to enjoy the benefits of CursiveDB.

using (SqlConnection conn = GetConnection())
	using (SqlCommand cmd = conn.OpenConnection().Query("update Author Set Name = @newName where Name = @oldName"))
			.AppendInputParam("@newName", "foo")
			.AppendInputParam("@oldName", "bar");
			.ExecuteNonQuery((affectedRowCount, source) =>
				Console.WriteLine("{0} rows affected", affectedRowCount);
Simple light-weight ORM support

In-built light-weight ORM support allows you to return class instances instead of Datasets or Data readers. Note, the support is very basic, if ORM is what you are after CursiveDB may not the library for you.

using (SqlConnection conn = new SqlConnection(connStr))
    IList authors = conn.Query("select * from Author").ResultSet();
    foreach(Author a in authors)
A SQL script runner

Just bundle up all your SQL statements like statements to create the schema plus insert stements to populate the initial master data into a text file. CursiveDB allows you to run this file against a database just like SQL Management Studio where blocks of SQL statements can be executed together by separating them from other blocks using the 'GO' keyword.

using (SqlConnection conn = GetConnection())
    string script = "c:\\test\insert_rows.sql";
    conn.ExecuteSqlScript(script, true);
Open source

CursiveDB is open source, you can either download the binaries or download the source code from gitlab. CursiveDB binary download comes with first-class help in .CHM format.

Usage help

The binary download of CursiveDB comes with a CHM help file which explains the syntax of methods as well as provides sample code. Coming soon - a quick-start blog which is a great starting point for using CursiveDB.

Pre-requisite software

  • .NET SDK 4.5
  • A development tool like Visual Studio