LINQ is actually a short form of Language Integrate Query,which can be used to retrieve data from any type of data source. LINQ is most important because data is the basic of any program and data can be easily retrieved from different types of data sources using LINQ.
Generally, data can be stored in many formats. That is, the data can be in the form of an XML file, can be in the form of relational database tables, can be in the form of Spreadsheet or can be in any other format. Before LINQ, different types of different syntaxes had to be used to retrieve the data stored in these different types of data sources.
But after adding LINQ to C#, we can very easily retrieve data from any data sources by the same syntax, while these syntax are also specified similarly to SQL (Standard Query Language).
That is, LINQ provides us such a capability that we can generate SQL Queries on LINQ Compatible Data Source, which was earlier possible only for any relational database.
The query we specify to retrieve data from LINQ Compatible Data Source is almost the same as the query in SQL. But this query is not fired on any relational database, but on any object of C#.
We can use LINQ with XML in the same way that we use it with SQL Data Source and in the same way we can use it with ADO.NET Datasets. That is, through LINQ, we can query data from different types of data sources by a single Common Language Syntax.
LINQ provides us a common way to query from different types of data sources. But apart from this, LINQ also provides a variety of solutions, which can also be used with other syntaxes added in C# such as Lambda Expressions, Anonymous Types and Extension Methods and to meet various types of specific requirements. could.
We can call C#'s LINQ as another language within a language. Therefore it is not possible to describe LINQ completely in one chapter. Rather a separate book could be written on LINQ only. Because LINQ is actually a C# implementation of a query language called SQL, which is used to query different types of data from different types of relational databases. So if we want, we can use LINQ as a SQL alternative in various ways to fulfill different types of database requirements.
LINQ Tutorial – The Fundamentals
The core concept of LINQ is Query itself. That is, LINQ is used in C# to query field objects from different types of data in the same way as we use SQL language to query a relational database.
As a query, we retrieve data from the data source on the basis of a specific condition or criteria and access and manipulate that retrieved data according to our needs. Query can be of different types, but each type of query returns some kind of data collection.
Once we have created a query based on our need, then that query can be executed. One way to execute the query is that we execute the query inside the foreach loop and every query is executed, some result is generated in the response of that query.
There are always two steps involved in executing a query. Query is created in the first step, while it is executed in the second step. So when we define query, then we are telling what we want to retrieve from data source and when we execute query, then we are obtaining actual data from data source .
For we can retrieve data from any data source through LINQ, it is necessary that we implement IEnumerable Interface. We can implement Generic IEnumerable<T> or Non-Generic IEnumerable as per our requirement. Whereas while implementing Generic Interface we need to set System.Collections.Generic Namespace
Importing is necessary in your program.
In the Relational Database System, the data is organized in the form of Normalized Tables and in the Relational Database, following the strict rules, various data are stored in Well Organized Tables, on which various types of SQL Queries are fired by the SQL Query Language. Data stored in tables is retrieved.
But in C# programs, data are stored in the form of Fields in Classes or Structures, there is a lot of difference in the way of storing data. Because Structure is always stored in Stack whereas Class always reserves space in Heap Area. As a result, no general query language could be developed to retrieve data from these different types of data structures before C# 3.0.
Because of which, in order to retrieve data from data structures in various programming languages, we always have to develop a custom design part of the program, through which the data of objects has been retrieved. As a solution to this problem, LINQ has been developed which provides the facility to query from a collection of objects.
LINQ is actually an extension of the .NET Framework, which provides the facility to fire collections of data in the C# programming language by creating queries similar to SQL Query. As a result, the way we retrieve records on the basis of Specific Criteria from different tables by firing SQL Query on a Relational Database, in the same way we fire LINQ Query on Collections of Data in C# Program same as SQL Query by Fire of Specific Criteria Data can be retrieve.