Monday, October 13, 2008

LinQ to SQL - Extending DataContext with Visual Studio 2008

Description:

This article explains how to add a .dbml file to work with SQL Server 2005 database. This process automatically extends DataContext class for your database and create code for you. This code can be modified according to the need. User can easily create Entity classes by drag and drop from Server Explorer.


Steps:

1. Right click on Project >> Add >> New Item

2. Select "LinQ to SQL classes". Give name as "Northwind.dbml" (If you are connecting with Northwind database).


3. Open Server Explorer and connect to Northwind database.

4. Expand Northwind database in Server Explorer and drag tables to Northiwind.dbml file area.







5. Northwind.designer.cs file has complete code for NorthwindDataContext and all entity classes.

No comments: