Introducing LINQ to SQL Designer using Visual Studio 2008
(Page 1 of 5 )
This is an introductory article that focuses on designing LINQ to SQL objects using the LINQ to SQL Designer in Visual Studio 2008. Apart from designing, we will concentrate on fetching and updating databases using the model created with Designer.
If you are a bit new to programming LINQ, please consider reading my previous article titled "Beginning 'LINQ to SQL' using Visual Studio 2008."
The entire source code for this article is available in the form of a free downloadable zip file. The solution was developed using Microsoft Visual Studio 2008 Team Edition on Microsoft Windows Server 2003 Standard Edition with Microsoft SQL Server 2005 Developer Edition. I didn't really test it in any other environment. I request that you post in the discussion area, if you have any problems in execution.
Creating a simple "LINQ to SQL" application: creating the project
In my previous article, we focused on "LINQ to SQL" development without working with a designer. "LINQ to SQL" designer is a great choice and has lots of features that we can take advantage of. We can take full advantage of it, if we know what it is doing internally.
Before going into complete internal details, let us start by creating a 'LINQ to SQL' application using a designer.
To make this article simple, I created two tables, "emp" and "dept," as follows:


The following are the steps used to create an ASP.NET 3.5 application with a "LINQ to SQL" designer:
Open Visual Studio 2008
Go to File || New || Project
In the "New Project" dialog, make sure ".NET Framework 3.5" is selected. In the "Project Type," select either "Visual Basic || Web" or "Visual C# || Web".
Select "ASP.NET Web Application" in the templates, provide the name of the application (Fig 3), and finally hit OK.

Creating a simple "LINQ to SQL" application: using "LINQ to SQL Designer"
The following steps are continued from previous section.
Right click on solution and go to Add || New Item (Fig 03)
Select "LINQ to SQL Classes" from the templates, provide the DataContext name and hit "Add". It is always recommended to provide a database name (unless you are working with multiple databases). The following is the screenshot (Fig 04):

If not already open, open "Server Explorer" (go to View || Server Explorer) and connect to your database. Make sure that you have both tables (along with their relationship) as mentioned in the previous section. The following gives you a better idea (Fig 05):

Drag and drop "dept" and "emp" from "Server Explorer" on to the designer (Fig 06).

Make sure "Web.Config" is modified with the connection string (should be automatic).
Next: Creating a simple LINQ to SQL application: fetching information onto a web page >>
More .NET Articles
More By Jagadish Chaterjee