Friday, September 08, 2006
The Missing LINQ
The jury is still out for me. I think LINQ (or Language INtegrated Query) is a cool technology. The problem for me is that it looks like SQL and SQL aint pretty. Ultimately LINQ will prove to be powerful, but I wonder if the SQL-like syntax will make code more or less abstruse. Throw in some lambda equations and the code looks messy (to me anyway).
Here is a DLINQ example, followed by a sample using lambda equation.
private static void DatabaseQuery()
{
Northwind db = new Northwind(
@"C:\Program Files\LINQ review\Data\Northwnd.mdf");
var match = from c in db.Customers
where c.Country == "USA" && c.ContactName.Contains("Yoshi")
orderby c.ContactName descending
select c;
foreach(var o in match)
Console.WriteLine("> {0} / {1} / {2}", o.CompanyName, o.ContactName, o.Country);
Console.ReadLine();
}
delegate T Func(T t);
private static void Lambda()
{
Func funcDel = delegate(int x){ return x+x; };
Func lambda = x => x+x;
Console.WriteLine(funcDel(5));
Console.WriteLine(lambda(5));
}
In both cases the code looks like it needs a lot of comments to describe what is happening, and things that need a lot of comments by implication aren't clear. Unclear is generally considered bad. (Did I mention SQL queries are ugly?!)
Well, it looks like LINQ, XLINQ, and DLINQ are here to stay, so let me see if I can get some mielage out of it.
Here is a DLINQ example, followed by a sample using lambda equation.
private static void DatabaseQuery()
{
Northwind db = new Northwind(
@"C:\Program Files\LINQ review\Data\Northwnd.mdf");
var match = from c in db.Customers
where c.Country == "USA" && c.ContactName.Contains("Yoshi")
orderby c.ContactName descending
select c;
foreach(var o in match)
Console.WriteLine("> {0} / {1} / {2}", o.CompanyName, o.ContactName, o.Country);
Console.ReadLine();
}
delegate T Func
private static void Lambda()
{
Func
Func
Console.WriteLine(funcDel(5));
Console.WriteLine(lambda(5));
}
In both cases the code looks like it needs a lot of comments to describe what is happening, and things that need a lot of comments by implication aren't clear. Unclear is generally considered bad. (Did I mention SQL queries are ugly?!)
Well, it looks like LINQ, XLINQ, and DLINQ are here to stay, so let me see if I can get some mielage out of it.
Subscribe to Posts [Atom]