Friday, August 29, 2008

[Tutorial] LINQ data query language
Part 1 - Setting up a project

This is the first part of a series that is dedicated to LINQ, which is a new data query language that was introduced with .NET framework 3.0. It facilitates and generalizes working with different kinds of data sources (LINQ To SQL, LINQ To XML, LINQ To Entities, etc).

This part shows how to configure a project for using LINQ and serves as fundament for all following parts. A console project is used for simplification but LINQ can be used in any type of project. The AdventureWorksDB is used for all data queries.

  • Add a new data connection to the project using the Server Explorer

  • Add a new item of type LINQ to SQL Classes to your project.

  • Some new files will be auto-generated and added to the project.

  • Open the dbml file and add some tables from the data source using the Server Explorer by dragging them to the design view of the dbml file.


  • Initialize an object of the auto-generated AdventureWorksDataContext class and display some product data.

  • Run the application and you will get the following output.


Share/Save/Bookmark

No comments: