Just sharing some of my inconsequential lunch conversations with you... RSS  

Wednesday, February 06, 2008

A "transactional" generic DbHelper for LINQ to SQL

Here's a nice little helper for those who intend to use LINQ to SQL. It will allow us to write something like:

DbHelper.Insert<Student>(
new Student()
{
FirstName = "Tanzim",
LastName = "Saqib",
Email = "me@TanzimSaqib.com",
Website = "http://www.TanzimSaqib.com"}, true); // Use Transaction?

Concise and elegant, isn't it? And what if we turn this around into an extension method, wouldn't it be yet another cool usage? Something like:

    new Student()
{
FirstName = "Tanzim",
LastName = "Saqib",
Email = "me@TanzimSaqib.com",
Website = "http://www.TanzimSaqib.com"}, true
).Insert(true /* Use Transaction */);

Oh, how I love C#3 and LINQ....

No comments:

Development Catharsis :: Copyright 2006 Mário Romano