A Simple LINQ to SQL Example
Before we dive into too many details, let’s see a simple example of using LINQ to SQL to interact
with the Inventory table of the AutoLot database created in Chapter 22. In this example, we will not
be making use of our AutoLotDAL.dll library, but will instead author all the code by hand. Create a
new Console Application named SimpleLinqToSqlApp and reference the System.Data.Linq.dll
assembly.
Next, insert a new C# class file named Inventory.cs. This file will define our entity class, which
requires decorating the type with various LINQ-centric attributes; therefore, be sure to specify you
are using the System.Data.Linq.Mapping and System.Data.Linq namespaces. With this detail out of
the way, here is the definition of the Inventory type:
[Table]
public class Inventory
{
C H A P T E R 2 4
■
P R O G R A M M I N G W I T H T H E L I N Q A P I S
844
8849CH24.qxd 10/19/07 10:11 AM Page 844
[Column]
public string Make;
[Column]
public string Color;
[Column]
public string PetName;
Do'stlaringiz bilan baham: |