Building a Simple Storefront with LINQ (Page 1 of 4 )
In this article, we'll take a look at data access in ASP.NET via LINQ by building a simple storefront (browse functionality) with ASP.NET. We'll use the light version of the Adventure Works Cycles sample database to provide data, and we'll access this data through LINQ to SQL. This article is the first part of a three-part series.
LINQ is a very promising and very powerful technology that allows various types of datasources to be queried in a unified way via the use of providers, such as LINQ to Objects, LINQ to SQL and LINQ to XML. Using LINQ in a regular Windows application is simple enough. All one has to do is drop a query straight into an assignment and then use the variable appropriately (for example, by looping over it and displaying the results). But what about web applications? How does one hook up LINQ and ASP.NET? And what features does ASP.NET provide to make LINQ usage simple?
The Adventure Works Cycles Sample Database
The Adventure Works Cycles sample database provides an example database with commerce data already in it. However, the full database is a bit too complex for our purposes, so we'll be using the light version of the database, which packs a smaller amount of data into only a handful of tables. This version of the sample database is better suited to explore basic concepts.
If you don't already have the database, it's a free download.
Download the appropriate installer for AdventureWorksLT. Then simply run the installer, which sets up the tables and inserts the data, providing everything that's needed to get started.
Create a new empty web site and add the Adventure Works database:

In the database explorer, you can see the tables provided:

In this article, we'll be using the Product tables. Let's take a quick look at each of these tables, starting with the Product table:

This table is, of course, where the basic details of each product are stored. Each product is assigned a unique ID, and each product is also assigned a ProductCategoryID and ProductModelID. The ProductCategoryID field corresponds to an entry in the ProductCategory table, and the ProductModelID field corresponds to an entry in the ProductMode table. We'll get to these tables in a moment, but take a look at the ThumbNailPhoto field. This stores a picture of the item in binary format. In order to display the image for each product, we'll need to create a page that extracts the binary representation of the picture from the database and then displays it.
Next: ProductCategory Table >>
More ASP.NET Articles
More By Peyton McCullough