Hello World: Linq to SQL

I used MSSQL Manager to create a table and put some data in it. I used Visual Studio to view that data. Big stuff. The connections are developing.

I learned about 'relationships'. This is something my old friend mysql does not have. Relationships enforce foreign keys. I made a pair of tables, item and category. Item had a column named category_id. When I made a relationship (using the diagram tool is pretty cool), I could not create an item with a bad category_id and I could not delete a row from categories for which an item existed. Seems like a good thing.

I am interested in heading into the Object Relation Mapper (ORM!) direction. As best I can tell, I will eventually use nHibernate. By all accounts, it's a rich, mature tool. However, .NET comes with something called Linq. It does a lightweight version of ORM (or so I've read) and I figure that it's the place to start on this.

My demo project is to create a small page that lists items, first based on a category that is hard-coded, later based on a select menu of some sort. I figure that this will allow me to experiment with Linq ORM and connecting it to the page in both directions.

This Wrox book I have* has a chapter on using Linq, bless their hearts. The basic idea is that I add a gridview object to my page, add a database object to the demo site using the Visual Studio (App_Data, new item, Linq to SQL, graphic tool to drag database tables to autocreate orm classes, cool stuff) and, put the database to gridview connection into the page_load event. Done. Try it out...

Big surprise, it doesn't work. Bigger surprise, it's not apparently my error, to wit:

Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

I google and find a page that says that I need to add a configuration element to my web.config file:

<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

This gets rid of the error message. Unfortunately, it doesn't give me data. Onward!

*Beginning ASP.NET 3.5 in C# and VB, ISBN: 978-0-470-18759-3 (Amazon)