Introduction to LINQ Query
LINQ query is similar to the SQL query created for developers to maintain a standardized coding approach. It deals with the data objects, therefore, it is similar to OOPs. All LINQ queries mostly have these operations in common.
- Obtain the data source: Ensure from where the data is going to come. We need to ensure the data source implicitly/ explicitly supports IEnumerable<T> interface.
- Create the query: Generate the query based on the requirement
- Execute the query
Why use LINQ Query
The biggest advantage of LINQ query is that it doesn’t load all the objects at the compile time. Instead, it creates an execution plan and when the compiler asks to perform its operation, then only the objects are loaded into memory.
Therefore, it is the fastest and most efficient way to code.
Let’s start with the project...
First, we will be adding the Entity Framework to our project. Here, I have used database first approach for this example. I created the database first and then I switched to coding.
The below steps will demonstrate how to include Entity Framework into the Visual Studio project.
- Right-click the project, click on Add and then add a new item.

- Choose ADO.NET Entity Data Model and click Add.

- Now, we have to use an existing database which we had created before. Therefore, choose EF Designer from the database. Then, click "Next".

- Now, choose the database and SQL Server and get the connection string. Then, click the "Finish" button. This step might take a long time to execute because the framework will generate essential classes and their relationship between them.

Following is the database structure that I have used.

Database explained
We assumed we have database for online learning. Relationships are clearly described in the above diagram. Following are the entities involved in the proposed database.
- Course: describes the set of courses
- Person : which enrolls for any course
- Author: creates course as many as they want
- Content: each course have one or many contents in it
- Course_comment: comment posted by user on particular course
- Content_comment: comment posted by user on particular content
- Content_rating: rating user gives to a particular content
Basic Select Query
As we know, we can get the list of our entity very easily with this approach. Now, let’s talk about the coding part where we used various basic operations such as select, join, and include in LINQ query.



Trevor NormanPosted Aug 24, 2020, 4:13 AM
Hi, I D/L'd the zip file and extracted the .sln, but when I try to open in VS 2019 I get an error... can't find part of the path. Please help...
Ben OkelloPosted May 10, 2018, 7:52 AM
Nice please elaborate More, if you had attached full code it would be helpful thankyou