A Newbie’s Intro to LINQ

Published 16 January 07 11:08 AM

I downloaded the Orcas January CTP recently because I was interested in getting my feet wet with LINQ – and even more interested in beginning to do some comparative analysis between a ADO.NET Entity Framework/LINQ solution and a NHibernate/HQL solution. How well that turns out, we'll just have to wait and see. However, just to get started, I fired up my VPC containing Orcas, created a new console app in Orcas, and entered the sample provided by the LINQ Project Overview. The code looked as follows.

   1:  using System; 
   2:  using System.Query; 
   3:  using System.Collections.Generic; 
   4:  using System.Text; 
   5:   
   6:  namespace Linq_Tests { 
   7:    class Program { 
   8:      static void Main(string[] args) { 
   9:        string[] names = {"Burke", "Connor", "Frank", 
  10:          "Everett", "Albert", "George", 
  11:          "Harris", "David"}; 
  12:   
  13:        IEnumerable<string> expr = from s in names 
  14:          where s.Length == 5 
  15:          orderby s 
  16:          select s.ToUpper(); 
  17:   
  18:        foreach (string item in expr) { 
  19:          Console.WriteLine(item); 
  20:        } 
  21:      } 
  22:    } 
  23:  } 

I then compiled the program only to receive the following compile error.

"The type or namespace name 'Query' does not exist in the namespace 'System' (are you missing an assembly reference?)"

Assembly reference – what's up with this? I then searched the assemblies listed by default in the VS assembly reference window – didn't see anything that looked like System.Query in there. Ah – then I remembered having a similar problem with the .NET 3.0 libraries when I started playing with those, so after a small amount of digging, I found that the assembly containing the LINQ namespaces is System.Core.dll and can be found at 'C:\WINDOWS\Microsoft.NET\Framework\v3.5.11209'. OK – cool – added that assembly reference. Same error. After a little more digging, I also discovered that the LINQ namespaces changed with the recent CTP from System.Query to System.Linq (see highlighted). Now, understand that this namespace reference does not apply to using LINQ to query XML or SQL data sources – you'll need different namespaces for those. Here's a really good post describing the January CTP. Also, here's a link to the C# 3.0 language specification.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# There and Back Again A Newbie s Intro to LINQ | Toe Nail Fungus said on June 13, 2009 6:53 AM:

PingBack from http://toenailfungusite.info/story.php?id=2924

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About hdierking

I am currently the Editor-in-Chief for MSDN Magazine. I joined Microsoft in 2006 as a product planner with the certification team at Microsoft Learning. Prior to that, I spent my career as a developer and later as an architect. My main technology passions include pretty much anything on language theory, agile development, and service-oriented architecture.
Page view tracker