On ZDNet: Fight Windows tax with a penguin stick

Is LINQ the future of database development?

Tags: C#, .NET, Programming languages, Benefits, Databases, Arthur Fuller, database, LINQ, See LINQ, SQL Server Newsletter

  • Save
  • Print
  • Recommend
  • 4

Takeaway: The LINQ (.NET Language Integrated Query) Project is an initiative to standardize data access across data sources and development. Arthur Fuller discusses LINQ and its benefits, and explains why he's not convinced that LINQ will revolutionize database application development.

The LINQ (.NET Language Integrated Query) Project is a Microsoft initiative to standardize data access across not only data sources but also development. A number of developers who have examined LINQ have proclaimed that it will revolutionize database application development.

I think LINQ has several hurdles to leap before we can adopt it seriously. However, LINQ does offer some interesting benefits, and as SQL developers and DBAs, it behooves us to learn about this new technology and its promises.

LINQ's benefits

LINQ's benefits include, most significantly, a standardized way to query not just tables in a relational database but also text files, XML files, and other data sources using identical syntax. A second benefit is the ability to use this standardized method from any .NET-compliant language such as C#, VB.NET, and others.

Weekly SQL tips in your inbox
TechRepublic's free SQL Server newsletter, delivered each Tuesday, contains hands-on tips that will help you become more adept with this powerful relational database management system.
Automatically sign up today!

See LINQ in action

The following snippet illustrates (in C#) a simple LINQ code block, using the Northwind database as its target. To see LINQ at work, we'll begin with a simple C# 3.0 program that uses the standard query operators to process the contents of an array.

using System;
using System.Query;
using System.Collections.Generic;

class app {
  static void Main() {
    string[] names = { "Alpha", "Brian", "Connie", "David",
                       "Frank", "George",
                       "Harry", "Inigo" };

    IEnumerable<string> expr = from s in names
                               where s.Length == 5
                               orderby s
                               select s.ToUpper();

    foreach (string item in expr)
      Console.WriteLine(item);
  }
}

This program delivers this output:

ALPHA
BRIAN
DAVID
FRANK
HARRY
INIGO

This example illustrates the coding style of LINQ and the movement of code to the front end that, in my opinion, should reside in the back end (even though I will admit that the code is clean and relatively transparent).

What front end and back end means to me


I'd like to offer this quick aside to discuss the terms front end and back end, which refer to the classic client-server configuration. The back end is the database itself, which resides on a server. The front end refers to the collection of client applications that speak to the database of interest; these might include apps written in any of the popular programming languages (e.g., Visual Basic, C++, and PHP). When talking about the front end, we must also include applications such as Microsoft Access, Excel, and Word.

In a small organization with fewer than 100 computers, say, these distinctions may seem academic, but my motto is "Design for success, otherwise you build failure in." That is why I want as much logic as possible to reside in the back end rather than the front end. Suppose I have a procedure or function that creates a recordset, qualifies the selection with one or more parameters, and then orders it by one or more columns. If I place the logic of that procedure in any given front end, then I will have to duplicate it in any new front end that is added next week or next month. Although we like to think that logic is independent of language, in practice, that is not the case.

Development has evolved from classic client-server to various forms of three-tier architecture (DLL-hell, SOAP, etc.). In these architectures, the front end talks to a middle tier which contains considerable logic and is addressable by all the front ends of interest. The middle tier speaks in turn to the database of interest. How you achieve this communication varies with the front end language and the middle-tier implementation, but suffice to say that this middle tier communicates with the database server and that the front end must only concern itself with talking to the middle tier. So I stretch the term back end to cover this architecture as well. My point here is that the front end should do as little as possible. If you use a middle tier, then move all the logic you can to that level, then reconsider your design and move all the logic you can to the back end.

My bias may be clouding my optimism


I must reveal that I hold this as a sacred principle: Whatever the back end can do, the back end should do. Given this bias, you can understand my reluctance to see database logic move into the front end.

Why am I so steadfast in this principle? Because, in my experience, several different front-end applications may hit a single database—they could be Web sites, Visual Studio apps, Delphi apps, and so on. To the extent that code moves from the back end to the front end, you must duplicate and translate the instructions from one front end to another. This is fine if you decide to stay within Visual Studio .NET, but suppose that you or your employer has other ideas? Or, what if you're interested in porting this logic to other databases?

My perspective is not unanimous. I know several developers who argue that certain applications and situations demand ad-hoc, dynamically constructed queries. I hold that these situations have not been analyzed sufficiently, but I am willing to be proven incorrect on this point. So let us examine the other perspective and assume that it is correct: There are N situations in which the only correct approach is to have the front end create a valid SQL statement, protect the code from SQL injection, and then pass the statement to the database engine.

Let us further assume that regardless of the correctness of either position, there are numerous developers who would like to develop their SQL instructions in the front end rather than the back end. It is this set of developers for whom LINQ is most interesting. To the extent that you subscribe to my sacred principle, you may find this movement toward the front end disturbing.

The jury is still out

It's too early to determine whether this new technology will be the next-best-thing in database development. For one thing, it still needs to be tested in the trenches of database and application development. I do think LINQ's multi-data source abstraction is very cool, but, as I've stated, I feel that the movement of code from the back end to the front end is inherently a mistake.

Only time will tell. But until that time when LINQ's advantages are proven (as compared to an equally functional database which contains the logic in the back end, leaving the front end with the trivial job of constructing calls to stored procedures and supplying the parameters they demand), I'm sticking with the "classic" approach: Whatever the back end can do, the back end should do.

  • Save
  • Print
  • Recommend
  • 4

Print/View all Posts Comments on this article

It is normal order of code for sql LukCAD | 10/17/05
But who started ASP.NET 2.O the provider model is more suitable LukCAD | 10/18/05
Different Perspective n3bu1a | 11/04/05
Down with RAD dbink | 10/18/05
N-Tier AbsoluteZero | 10/18/05
Developers in the DB jimpen | 10/18/05
Same song, different day bernardreagan@... | 10/19/05
Missing the point? mtan | 10/19/05
semantic level? Elmonk | 01/09/08
This is where it will Excel ! dennis.williams@... | 10/20/05
I thought Excel was a SpreadSheet KaptKos | 11/03/05
Process weight istari2ve2002@... | 11/03/05
Server-side LINQ Filip Verhaeghe | 12/20/05
LINQ lets the developer decide robocso@... | 01/09/08
Absolutely right k.stafferton@... | 01/09/08
RE: Is LINQ the future of database development? rupeshp@... | 10/23/08

What do you think?

White Papers, Webcasts, and Downloads

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET

Product Spotlight

advertisement
Click Here