Nemerle includes SQL macros. These make writing basic ADO.NET code a lot easier. They won't replace a complex ORM solution, but are fantastic for quick data access code. The main win is compile time query checking! That's right... if you misspell a column, table, etc, you get a compile error.
Watch the Screencast
Before
using System;
using System.Data.SqlClient;
namespace Demo
{ module Program
{ Main() : void
{ using (conn = SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=SSPI"))
{ conn.Open();
using (cmd = SqlCommand("select Id, FirstName, LastName from Customer where IsPrefered=1", conn)) { using (reader = cmd.ExecuteReader())
{ while (reader.Read())
{ def id = reader.GetInt32(0);
def firstName = reader.GetString(1);
def lastName = reader.GetString(2);
Console.WriteLine("{0}: {1} {2}", id, firstName, lastName); }
}
}
}
_ = Console.ReadLine();
}
}
}
After
using System;
using System.Data.SqlClient;
using Nemerle.Data;
[assembly: ConfigureConnection("System.Data.SqlClient.SqlConnection", @"Data Source=(local)\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=SSPI")]
namespace Demo
{ module Program
{ Main() : void
{ using (conn = SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Customers;Integrated Security=SSPI"))
{ conn.Open();
ExecuteReaderLoop("select id, firstName, lastName from Customer where IsPrefered=1", conn, { Console.WriteLine("{0}: {1} {2}", id, firstName, lastName); });
}
_ = Console.ReadLine();
}
}
}