In this article we will learn LINQ. The article explains what LINQ is, why to use LINQ and how to use LINQ.
IntroductionIn this article we will learn LINQ. The article explains what LINQ is, why to use LINQ and how to use LINQ. When there was already ADO.NET technology with .NET then why another data access technology? What are the problems solved using LINQ? These are all the things in this article.The following are the topics covered:
What LINQ isLanguage Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, including Java, PHP, JavaScript and ActionScript. Let's try to understand what exactly "Language Integrated" means. LINQ is part of programming language syntax. And query means LINQ is used for querying the data. The data would be any type, relational type data and objects too. So we can say that a LINQ is a Programming language syntax used to query data.Let's try to understand what ADO.NET is then why LINQ. ADO.NET is an object-oriented library and uses data from a relational perspective. We can bind ADO.NET objects directly into a user interface. But we often need a translation, like ADO.NET data into Business Objects with relationships, rules and semantics that do not translate automatically from a relational store. LINQ does remove these kinds of problems and re-shape our data as an object. LINQ also defines a set of methods names called standard query operators, or standard sequence operators along with translation rules used by the compiler to translate a fluent style of query expressions using these methods names, lambda expressions and anonymous types.
How to write LINQ QueryBefore writing a LINQ query we should understand the basic syntax of LINQ. There are the following three ways to write a LINQ query.
Query SyntaxThis is the basic and simplest way to write a query using query syntax. In query syntax we must use a query expression. In a query expression the first expression demonstrates how to filter records by applying a where clause, this will return all the elements determined by the condition passed in the where clause.Example
Method Syntax
When a query is written with a method call and returns a single numeric value, like Max, SUM, Min and many others. These methods must always be called last of any query because they represent only by a single value and cannot serve as the source for an additional query.Example
Combination of query syntax and method syntax
Mixed Query and Method Syntax will help to use a single query with a method as well as a simple query.Example
Summary
Pro WPF: Windows Presentation Foundation in .NET 3.0