Monetize your website with Chitika eMiniMalls
Powered by MaxBlogPress 

Bluehost - Affordable, Reliable Web Hosting Solutions
Powered by MaxBlogPress 

Why use LINQ to SQL?

Posted on May 23, 2008
Filed Under Development | 1 Comment

If you've enjoyed reading this post then please subscribe to my Full Text RSS Feed.

I’ve been doing .NET development for some years now and I am comfortable using ADO data access to SQL Server for persistent database data. Since moving from .NET 2.0 to .NET 3.5, I am challenged to rethink on data access. Why has Microsoft decided to create LINQ to SQL data access in .NET 3.5 Framework and cause such a revolutionary paradigm change in how web applications interact with databases.

I have been writing Transact-SQL code for years and know it very well. Why do I have to adopt LINQ? The answer is I don’t have to but there are benefits. After reading ASP.NET 3.5 Unleashed by Stephen Walther, I can see why LINQ is beneficial. According to Stephen Walther,

“A vast chasm separates the way developers work in transient application data and the way developers work with persistent database data. In our applications, we work with objects and properties (created either in VB.NET or C#). In most databases, on the other hand, we work with tables and columns.”

What it means is our applications and our databases are used to represent the very same data. Example, we have a product class and a product database table named product that represents a list of products we sell through our website but the language we use to interact with the product class and product table are very different. If you are not a database programmer, you will know that programming in VB.NET or C# is very different from programming in Transact SQL.

In organisations where they have a larger team of developers, they will usually have the object programmers (the VB.NET and C# team) and they will have the database/SQL programmers team. Both are specialist areas of software development. Microsoft saw that it took a lot of time translating between object and relational universes. ADO adapters are great but Microsoft saw that by introducing LINQ to SQL, they could possibly retire ADO and SQL.

My question is how much can LINQ replace SQL?
I know LINQ has its equivalent of SQL’s SELECT, INSERT, UPDATE, DELETE but can LINQ replace triggers, cursors, views, functions. My guess would be no. Stephen Walther says that SQL is like plumbing and in this world of DIY, if a job gets too complicated, you call in the plumber. SQL will remain a specialist area of development but simplified by LINQ for non-SQL programmers.

If you think about SQL Server Reporting Services (SSRS) that comes with SQL Server, SSRS is a popular tool. Many organisations use SQL Server simply because of SSRS. To develop reports using SSRS, you must know Transact SQL. Some may argue that SSRS has an embedded VBScript engine but that is to supplement not replace report creation using SSRS. Based on this point, I know we will not see the death of SQL anywhere sooner than we expect.

Understanding LINQ
Building a LINQ query is like building a backward SQL query.

SQL example
SELECT * FROM product WHERE country = ‘UK’

LINQ example
var results = from p in products
where p.country == “UK”
select w;

.NET translates the LINQ queries to methods and when translated the query will be:

var results = products.Where(p => p.country == “UK”).Select (p => p);

So do I like LINQ to SQL…No I don’t but that doesn’t mean I won’t learn it. I will tell you why. I am a C# developer and a hybrid SQL Server database administrator. I am comfortable writing code in objects, properties and methods and I am also comfortable writing script in Transact SQL. That is why.

Note: In order to use LINQ, you’ll need .NET Framework 3.5 and an IDE such as VS 2008 or Visual Web Developer 2008.

Bookmark and Share
Sphere: Related Content

Other Related Posts:

  • No related posts

  • If you've enjoyed reading this post then why not subscribe to received updates by email.

    Enter your email address:

    Delivered by FeedBurner

    Email This Post Email This Post

    Trackback This Post

    Comments

    One Response to “Why use LINQ to SQL?”

    1. Code Principles on June 5th, 2008 6:34 pm

      Wow, same here. .Net programmer, forced database administrator, and excellent T-SQL and PL/SQL writer.

      LINQ looks great for .NET objects, but for replacing SQL, I will learn it, but stick with my bread and butter.

    Leave a Reply




    CommentLuv Enabled

    Twitter

    Posting tweet...

    Powered by Twitter Tools