LINQ stands for Language Integrated Query. In this linq tutorial we are covering linq to object in which we have shared the example of linq to array, linq to jagged array, linq to list, lambda expression. In linq to SQL we have shared the example of Insert, update, select and delete from database using linq. In Linq to entity we have shared the communication between sql and using entity framework. In linq to xml we have shared how to select, manupulate and traverse xml file with example.

LINQ To Object

LINQ to Array

Language Integrated Query introduced in .net framework 3.5. LINQ integrated accessibility of data and query into language. LINQ makes easier to work with data.

Linq to Array

LINQ to Jagged Array

We can also traverse jagged array using LINQ.

linq to jagged array


In this tutorial we will discuss how to work with LIST using LINQ. For this example i am going to use the user defined data i.e. class. Create class and add some variable in it. I created the class name TechAltum and add some variable in it which is as follows:-

linq to list

Var in LINQ

Var is data type in C# which holds the anonymous data. When you do not know the return type we can hold data in var. The declaration and definition of var type will be declare in the same line.

var in linq

Lambda Expression in LINQ

A lambda expression is an anonymous function. Using lambda expression we can create function for delegate and we can also create expression tree type.

lambda expression

Random in LINQ

In linq if we have requirement to show data randomly then we can use Random class with linq to perfume this task.

random in linq

SelectMany in LINQ

SelectMany projects each elements result into one sequence i.e IEnumerable<T>.

select many in linq


LINQ to SQL Select

SQL is a structured Query Language. When we need to interact with database using LINQ then we mapped our relational database to object oriented language using LINQ to SQL.

To interact with database we use DataContext class which is in System.Data.LINQ. This class contains the constructor in which we have to pass the connection string.

linq to sql

LINQ to SQL Insert

When we insert using LINQ then your table must have primary key. So the table which I was using not contain primary key. So I added one more column name id in the table which is primary and auto generated (used identity). So I have to make following changes in the class which maps my table to object oriented language which is as follows:-

linq to sql insert

LINQ to SQL Delete

We use the following code to delete from the database using LINQ:-

linq to sql delete

LINQ to SQL Update

We use the following code to update from the database using LINQ:-

linq to sql update

Aggregate Function in LINQ

Implementation of Aggregate function with Array, Generics and Database

We use many aggregate functions like sum, count, average, min, and max. In LINQ we can use this function in the following manner:-

aggregate function in linq

Long Count in LINQ

Long count is similar to count as it works same but the only difference between them is that long count returns a 64 bit integer.

long count in linq

Sorting in LINQ

Implementation of Sorting with Array, Generics and Database

To sort data in LINQ we use orderby in the following manner:-

sorting in linq

Set Operation in LINQ

Implementation of Set Operation in LINQ

We use following set operations in LINQ:-

set operation in linq


Create XML

When we interact with XML using LINQ then it is known as LINQ to XML

To work with XML in LINQ you have to add a namespace using System.Xml.Linq.

how to create xml in linq

Traverse XML File using LINQ

In my last article I explained how we can create XML file using LINQ. In this article I will discuss how we can traverse this XML file using LINQ.

how to traverse xml in linq

Concat Method in LINQ


Concat method is used to concat two data sources. In my last article I used union method to concat two data sources.

Concat in linq

Take, TakeWhile & Skip, SkipWhile

Take & TakeWhile

Take is used to take the value from the beginning according to your count. It will work like top command which we use in SQL.

take and take while in linq

Skip & SkipWhile

Skip in LINQ is used to skip values from the beginning. We pass a numeric value to skip which represent that how many values we need to skip.

skip and skip while in linq