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.
Comments 5
I’m the author of WebMatrix.Data and I just want to say that we do support generic ADO.NET providers. The only odd ball method that doesn’t really work for all providers (since it’s not abstracted well) is GetLastInsertId(). Do you special case providers to handle that method?
Posted 22 jan 2011 at 20 h 12 min ¶I thought so but the various announcements were really SQL Server specific hence why I wanted to show it working with something else.
And no GetLastInsertId is also the culprit for us, for the moment I simply put the SQL Server method. I’ll see for a way to cross-DB this.
Posted 23 jan 2011 at 15 h 45 min ¶I’m testing WebMatrix.Data using Npgsql provider but it throw error
System.InvalidCastException: Cannot cast from source type to destination type.
at Npgsql.NpgsqlFactory.CreateConnection () [0x00000] in :0
at WebMatrix.Data.Database.OpenConnectionString (System.String connectionString, System.String providerName) [0x00000] in :0
after run into this problem i found that Npsql DbProviderFactory throw this error on Mono
Posted 10 fév 2011 at 6 h 09 min ¶but it is ok in .NET any info about this
Could you add that as a bug report with a test case on http://bugzilla.novell.com please?
Posted 12 fév 2011 at 16 h 24 min ¶That is teh sexors.
Posted 12 avr 2011 at 15 h 23 min ¶Trackbacks & Pingbacks 1
[...] bundled with Mono as is the case with previous versions. There is also some preliminary support for WebMatrix in the form of WebMatrix.Data.dll and Razor. I didn’t have the time to play with any of these, so if you have some experience [...]
Post a Comment