+92 332 4229 857 99ProjectIdeas@Gmail.com

How to add database to project (LINQ To SQL)

In this tutorial you will come to know how we can add database to project all the steps that is necessary. 
Step 1
Start a new project and then go to solution properties then go to Add and then New Item, see following figure:

Step 2
After selecting New Item this window will open and here you select Data and then in its corresponding select LINQ to SQL Classes, and then click on Add button see below:

Step 3
After clicking on Add button the following designer window will open where you select Server Explorer.

Step 4
When you select a Server Explorer a side window will open, there you must select Data Connections and right click on it and choose Add New Connection, see below:

After clicking on Add New Connection the above window will open and you must select a database to which you want to connect. Here I am choosing MyFirst and click Ok button.

Step 5
In this step: expand your database and go to Tables and select the tables, here my database contains two tables Customer and Item so I am selecting both, see below:

Step 6
Select the tables (Customer and Item) and drag them to designer and you see the following view, where all the tables are placed with their Column Names and whatever you define any Relations between tables, here is the relation between Customer “ID” as primary key and in the table Item “CustomerID” as foreign key, so in this way we can get which customer buys which item.

In the next post we'll see how we can query on this database. And through different queries how we can get our desired data from database.