What is LINQ?LINQ is known as Language Integrated Query, and it is presented in .NET 3.5 and Visual Studio 2008. The excellence of LINQ is it gives the capacity to .NET languages(like C#, VB.NET, and so forth) to create inquiries to recover information from the information source. For instance, a program might get data from the understudy records or get to worker records, and so on. In previous years, such sort of information is put away in a different data set from the application, and you really want to learn various kinds of question language to access such kind of information like SQL, XML, and so forth. And furthermore, you can't make a question utilizing C# language or some other .NET language. To beat such kinds of issues, Microsoft created LINQ. It connects one more capacity to the C# or .NET dialects to create a question for any LINQ viable information source. What's more, the best part is the sentence structure used to make a question is similar regardless of which kind of information source is utilized means the grammar of making an inquiry about information in a social data set is the same as that used to make question information put away in a cluster there is compelling reason need to utilize SQL or some other non-.NET language component. You can likewise utilize LINQ with SQL, with XML records, with ADO.NET, with web administrations, and with some other information base. In C#, LINQ is available in System. Linq namespace. It gives different sort of classes and techniques which upholds LINQ questions. In this namespace:
For Example: SQL is a structured query Language that is used to save and recuperate data from the database. Likewise, LINQ is an Organized Query Sentence structure. LINQ is the basic C#. It is utilized to recover information from various kinds of sources, for example, XML, docs, collections, ADO.Net DataSet, Web Service, MS SQL Server, and different database servers. Uses of LINQ
We can use LINQ queries in two waysLINQ query Syntax structure is comprised of query keywords which are characterized into the .NET System rendition 3.5 or Higher. This allows the software engineer or developers to compose the directions very much like SQL design in the code(C# or VB.NET) without the utilization of rates. It is in like manner known in light of the fact that the Question Articulation Grammar. In LINQ, you can compose the inquiry to IEnumerable series or IQueryable information sources utilizing the ensuing strategies: 1. Query Syntax:The LINQ query language syntax starts with from keyword and finishes with the Select or GroupBy keyword. After from keyword, you can utilize various sorts of Standard Query operations like grouping, filtering, and so on, as indicated by your need. In LINQ, 50 unique kinds of Standard Question Administrators are accessible. Steps for writing the Query syntax: Step-1: In the first step, we have to add the System.Linq namespace in the code. Step-2: In a second step, we have to create the data source on which we have to perform the operations Step-3: In the third step, we have to create the query for the data source using a keyword like select, from, etc. Here r is the query variable that stores the result of the query articulation. The form clause is utilized to determine the information source, i.e., list, where condition applies to the channel, i.e., l.Contains(" Hii ") and select statement gives the kind of the brought things back. Furthermore, l is the reach variable. Step-4: The final step is to execute the query using the for each loop. Example program on Query syntax: Output: 2. Method SyntaxIn LINQ, Method Syntax is utilized to call the expansion method for the Enumerable or Queryable static classes. It is also called Method Extension Syntax or Fluent. Notwithstanding, the compiler generally changes over the query syntax in method syntax structure at compile time. It can summon the standard Query operator like Where, Join, Max, Min, Avg, GroupBy Select, and so forth. You are permitted to call them straightforwardly without utilizing Query syntax. Step-1: In the first step, we have to add the System.Linq namespace in the code. Step-2: In a second step, we have to create the data source on which we have to perform the operations Step-3: Now create the query using the methods provided by the Enumerable or Queryable static classes Here r is the query variable that stores the result of the query articulation. The form clause is utilized to determine the information source, i.e., list, where condition applies to the channel, i.e., l.Contains(" Hii ") and select statement gives the kind of the brought things back. Furthermore, l is the reach variable. Step-4: The final step is to execute the query using the for each loop. Example program on Method syntax: Output: Advantages of LINQ
Next TopicNZEC in Java
|