WebMatrix.Data on Mono
Initial reading on what is WebMatrix can be found on Scott Guthrie blog.
After team WebMatrix was formed this week, I have reimplemented the Data part of WebMatrix, a cute layer on top of ADO.NET with support for the dynamic
keyword (C# 4) so that you can directly call property equivalent to your column names.
Bonus point is that even though is has been shipped with a heavy slant towards SQL Server (and its new compact counterpart) since it’s implemented on top of stock System.Data.Common we can use any provider with it including the great old-fashioned SQlite provider.
Say I have the following SQlite database:
That is populated with these values:
You can now write code like this to query the database:
using System;
using WebMatrix.Data;
class WebMatrixSample
{
public static void Main ()
{
var db = Database.OpenConnectionString ("Data Source=sqlite.db;Version=3;", "Mono.Data.Sqlite");
var result = db.Query ("select * from Phonebook where Number glob '0*'");
foreach (dynamic row in result)
Console.WriteLine ("({0:D2}) {1}: [{2}]", row.Id, row.Name, row.Number);
var entry = db.QuerySingle ("select * from Phonebook where Name = @0", "Rupert");
Console.WriteLine ("Rupert number is {0} with id {1}", entry.Number, entry.Id);
Console.WriteLine ("but really his number is just {0}",
db.QueryValue ("select Number from Phonebook where Name = @0", "Rupert"));
// And let's add my bank number
db.Execute ("insert into Phonebook(Name, Number) values (@0, @1)", "Bank", "01xxxxxxx");
}
}
WebMatrix.Data assembly is now available when you compile Mono from Git master.