Search Eridotnet


Tuesday, January 8, 2008

Quick thoughts on .NET 1.x, 2.0, 3.0 and 3.5 (part three)

Now, the top "buzzword" for .NET 3.5: LINQ. Yes, it's here, released. It's not for VS 2005 anymore. It's good for VS 2008. But it's not all of that shiny new concept feature.

Let's talk LINQ!

LINQ is one of many ways of solving the problem of "impedance mismatch of relational data and objects", which has been around for years. More about this, see here, and here ("The Vietnam of computer science"), and the response of it on CodeProject.

Although there are many ORM product that's been trying to solve this and in some degrees they solved it, none of them offer the deep integration of query language inside the general language programming such as C# and VB.NET. As a side effect, many has asked, "Is ORM tools dead?" But none of this make enough sense for me. LINQ is not meant to kill other ORM tools! Believe it or not, comparing to some aspects of IdeaBlade DevForce and Wilson's ORM, LINQ is still a long way to go, and LINQ shouldn't be used alone.

Some sample uses of LINQ

This is the easiest sample of LINQ, try to do SELECT query. I'm now querying the available (collection of) running processes in my computer (yes, LINQ can query collections).

First, make a Console project using C# or VB.NET before running this sample.

This is the code example (taken from Anders Hejlsberg's video):

In C#:

    class Program
static void Main(string[] args)
Console.WriteLine("LINQ Sample");
Console.WriteLine("listing of my running processes");
var runproc1 = from Process p in Process.GetProcesses()
select new { p.Id, p.WorkingSet64 };
foreach (var proc in runproc1)
Console.WriteLine("{0} size={1}", proc.Id, proc.WorkingSet64);


Module Module1

Sub Main()
Dim query = From p As Process In Process.GetProcesses() _
Select p.Id, p.WorkingSet64
For Each proc In query
Console.WriteLine("{0} size={1}", proc.Id, proc.WorkingSet64)
End Sub


Those two codes above will display current running processes on your machine with the id and working set. You can also display ProcessName if you want to. It's simple, right?

Actually, query variable is of type IEnumerable<T>. This means you can treat query as a collection and it's also queryable.

Now, enough introduction. LINQ is actually consisting of:

  • LINQ to Objects (it's the sample above)
  • LINQ to XML
  • LINQ to DataSet
  • LINQ to Entity (part of the ADO.NET Entity Framework)

Note, that LINQ to SQL only works for SQL Server 2005 and above, but not for others such as Oracle or IBM DB2.

If you're using VS 2008, you can code using DLINQ generated object and have them queryed directly. Later post on more on DLINQ.

But, there'll be more about .NET 3.5! I'll try to bring you more LINQ and the other new goodies in .NET 3.5.

What about .NET 3.0? In future posts I'll also make some flashback to .NET 3.0, where the buzzwords are WPF,WCF,WF, and CardSpace (although sadly enough there are very little examples and resources about CardSpace).

kick it on


Cipto KH said...

Whow LinQ keren juga ya, merubah cara programming menjadi mirip SQL syntax

Eriawan BlogSpot said...

Thank you, Cipto!

Sebetulnya masih sama aja cara programmingnya, cuman ditambah SQL syntax. Sayangnya masih terbatas pada SELECT query, belom bisa INSERT, UPDATE, DELETE.

Kalo ingin INSERT dan UPDATE, tinggal memakai fasilitas extension methods dari C# 3.0 atau VB 9.0, yang semua ini ada di VS 2008.

Cip, tau CodeGear kan? Dengan release terbaru mereka, Delphi "11", sudah siap mendukung .NET 3.5, dan bakal ada LINQ versi mereka sendiri.

Seingatku kamu kayaknya lebih comfortable code di Delphi. Silakan cari Delphi 11 yah? Kalo dapet, bagi2, hehhehe....