An Overview Of LINQ

Synapsis:

  • Introduction
  • Syntax
  • Advantages
  • Types
  • Operators

Introduction about LINQ

LINQ Stands for Language Integrated query which is used to access memory objects, Databases and XML documents and so on.

LINQ is designed by Anders Hejlsberg and it is introduced by Visual Studio 2008.

Syntax for LINQ:

Lambda Expression:

Var Val = value. Where (Val<=5);


Query Syntax:

Var Val = from val in Value Where val> 10;

Advantages:

  • It offers Syntax Highlighting to find out errors during Design time.
  • Write queries easily
  • Development time is reduced.
  • Easy debugging
  • Transformation of data from one to another easily like SQL to XML

Types of LINQ:

  • LINQ to objects
  • LINQ to SQL(DLINQ)
  • LINQ to dataset
  • LINQ to XML(XLINQ)
  • LINQ to entities

LINQ Query Operators:

Query operators are identified based on their functionalities.

  • Filtering Operators
  • Join Operators
  • Projection Operations
  • Sorting Operators
  • Grouping Operators
  • Conversions
  • Concatenation
  • Aggregation
  • Quantifier Operations
  • Partition Operations
  • Generation Operations
  • Set Operations
  • Equality
  • Element Operators

Let us discuss these operators in detail.

Filtering Operators:

Used to select (or) filter particular object based on the condition.

The Operators used for filter is,

  • Where
  • ofType

Join Operators:

Based on the query condition the Join operators are used to join the row or column of the particular tables.

The Operators used for Join is,

  • join – join two matching key values
  • GroupJoin – join key values and grouping that two matching values

Projection Operations:

Project values show the values of particular specific keys.

The Operators used for Projection is,

  • Select
  • SelectMany

Sorting Operators:

It allows us to arrange the elements based on the sequence

The Operators used for Sorting are,

  • OrderBy
  • OrderByDescending
  • ThenBy
  • ThenByDescending\
  • Reverse

Grouping Operators:

It is used to group the values based on a common attribute.

The Operators used for Grouping are,

  • GroupBy
  • ToLookup

Conversions:

It is used to change the type of the Input.

The Operators used for Conversion  are,

  • AsEnumerable
  • AsQueryable
  • Cast
  • OfType
  • ToArray
  • ToDictionary
  • ToList
  • ToLookup

Concatenation:

It is used to unite two values.

The Operators used for Concatenation are,

  • Concat

Aggregation:

It is used to Aggregate (or) grouping (or) or for getting sum of values.
The Operators used for Aggregation is,

  • Aggregate
  • Average
  • Count
  • LonCount
  • Max
  • Min
  • Sum

Quantifier Operations:

This is used to return Boolean Values that are True or False.

The Operators used for Quantifier are,

  • All
  • Any
  • Contains

Partition Operators:

It is used to divide the input sections into two separate sequences and return them.

The Operators used for Partition are,

  • Skip
  • SkipWhile
  • Take
  • TakeWhile

Generation Operations:

New sequence values created.

The Operators used for Generation are,

  • DefaultIfEmpty
  • Empty
  • Range
  • Repeat

Set Operations:

Getting the result based on the criteria.

The Operators used for Set Operation are,

  • Distinct
  • Except
  • Intersect
  • Union

Equality:

It is used to compare two values and find whether  those values are an exact match or not.

The Operators used for Equality are,

  • SequenceEqual

Element Operators:

The Operators used for Element are,

  • ElementAt
  • ElementAtOrDefault
  • First
  • FirstOrDefault
  • Last
  • LastOrDefault
  • Single
  • SingleOrDefult
  • DefaultIfEmpty

We will discuss the types of LINQ to my next article. Thanks.

Read more articles on LINQ:

Up Next
    Ebook Download
    View all
    Learn
    View all