LINQ (Language Integrated Query) - Part 4

This is fourth part of the ‘LINQ’ series posts that I have started from here. And in this post, you will learn how to setup a demo project to explore LINQ queries. I will use my preinstalled ‘Northwind’ database that you can download from here and install it in SQL Server Management Studio.

Previous Posts:

Video Post here:

Now, follow the steps to setup a demo project to explore LINQ queries. Before creating new project, setup a ‘Northwind’ database in SQL Server Management Studio.

Step 1: Creating New Project

Open the Visual Studio instance and create a new project New > Project > Console Application and name the project whatever you wish.

Step 2: Adding LINQ to SQL Classes

Now, in the solution explorer add a new item ‘LINQ to SQL Classes’ by a nice name ‘DataNorthwind.dbml’.

This will add all required library as well as classes in your project for database communication. Actually, this dbml file will become a layer between DB and your project and provide you all the IntelliSense features.

Step 3: Adding New Connection

Open ‘Server Explorer’ and add a new SQL Server connection, follow the image.

Once you done with above, now drag the tables from ‘Server Explorer’ to ‘DataNorthwind.dbml’ file designer.

Now, you will get following DB digram on designer.

You will notice following things here:

1. Got a new connection string in App.config file.
2. Got every setup required to communicate with DB like DataNorthwindDataContext, TableAttribute, EntitySet etc in DataNorthwind.designer.cs file.

Step 4: Coding and Running Project

Now, setup the project code as given blow and run it.

We already seen this code in one of the previous post. Now, we have a demo project setup completely and ready to try all the LINQ queries.

In upcoming post, we will look at various LINQ queries and will test it in above project.

I hope you will find it useful. Thanks for reading.


Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples