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:
Post a Comment