Click to See Complete Forum and Search --> : Linq


boudino
October 24th, 2005, 08:27 AM
Hi all

Do you hear/read about LINQ? It is a feature of future version of C# - C# 3.0. It can seem that it is quite early to take care about it, but I think we should start discuss it soon if we want to change something about it.

Quickly, LINQ incorporates (pseudo) SQL syntax into C# to allow programer easy manipulate and query collection. More informations can be found on http://msdn.microsoft.com/netframework/future/linq/ and many examples on http://msdn.microsoft.com/vcsharp/future/linqsamples/

LINQ can looks like:
string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };

var upperLowerWords =
from w in words
select new {Upper = w.ToUpper(), Lower = w.ToLower()}
where w.StartsWith("a");

I very wellcome whats behind LINQ and whats it can provide, but I think it is confusing to breed C# language syntax with SQL syntax. I believe it is a way to the ****. It is unnecessary, C# constructs is everything we need.

I suggest following approach which fully respects C# 3.0 syntax (it uses so called Lambda calculus):

string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };

var selectedWords = words.Select(w => {return w.StartsWith("a")});
var projection = Collect(w2 => {return new {
Upper = w2.ToUpper(),
Lower = w2.ToLower()};
(I have splited it into to statements only for typographical reasons).

I prefer to have only methods in combination with lambda calculus (which is an advanced form of anonymous methods from C# 2.0).

What is your opinion? What do you think about my approach?

(I want no flamewar here, so please do dont argue with others, just post your opinion).

boudino
October 25th, 2005, 03:19 AM
I've recently recieved answer on Microsoft's forum, that points me to http://download.microsoft.com/download/c/f/b/cfbbc093-f3b3-4fdb-a170-604db2e29e99/Standard%20Query%20Operators.doc

In conlusion - what I am suggestiong is possible; what I am refusing is only syntactical sugar. But I still believe that the syntactic sugar should be rejected. Let me to cite myself: I think it is danger, because it makes ilusion that there a relation data model behind it. I know that OQL has similar syntax to SQL, I just think that the syntactic sugar is unnecessary and confusing.