Category Archives: Linq

Difference between Select and SelectMany in LINQ

Select is used to select value from a collection whereas SelectMany is used to select values from a collection of collection i.e. nested collection. Select and SelectMany both are projection operators. In below example we will return a list of courses, each containing a list of subjects. You will see that Select will return a… Read More »

LINQ Single vs SingleOrDefault vs First vs FirstOrDefault

Single(), SingleOrDefault(), First() and FirstOrDefault() are extension methods of the Enumerable class. Many people get confused about the difference between Single, SingleOrDefault, First, and FirstOrDefault methods in Linq. Let’s understand the difference between all these methods as below: Single() SingleOrDefault() First() FirstOrDefault() Description Returns a single, specific element of a sequence Returns a single, specific… Read More »

Difference between Lazy Loading and Eager Loading

Lazy/Deferred Loading In lazy loading, related objects (child objects) are not loaded automatically with its parent object until they are requested. By default LINQ supports lazy loading. With Lazy Loading, we only retrieve just the amount of data, which we need in a single query. When we need more data related to the initial data,… Read More »

Generate random number using Linq

In below example, we will show how to generate random number using Linq in C# public static string RandomString(int length) { const string chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789”; var random = new Random(); return new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray()); }

Linq with an example

LINQ (Language Integrated Query) Designers over the world have experienced issues in querying because they have to master on multiple querying languages such as SQL, Web Administrations, XQuery, and so forth. In Visual Studio 2008 an inbuilt querying language was incorporated called LINQ(Language Integrated Query) outlined by Anders Hejlsberg. It permits composing queries even without… Read More »

What is LINQ

LINQ(Language Integrated Query) introduced in .NET Framework 3.0(VS 2008).Linq queries are object oriented languages\queries.It enables the query of data from any kind of data source, including databases, XML, List, Array and so on. It offers a compact, expressive, and intelligible syntax for manipulating data. It is required as it bridges the gap between the world… Read More »

LINQ Operators and Lambda Expression

Lambda expression in Linq It is referred as a unique function use to form delegates or expression tree types, where right side is the output and left side is the input to the method. For writing LINQ queries particularly, Lambda expression is used. Where IEnumerable<Product> x = products.Where(p => p.UnitPrice >= 10); IEnumerable<Product> x =… Read More »


PLINQ stands for Parallel Language Integrated Query. It is the parallel implementation of LINQ, in which a query can be executed by using multiple processors. PLINQ ensures the scalability of software on parallel processors in the execution environment. It is used where data grows rapidly, such as in telecom industry or where data is heterogeneous.… Read More »

Advantages and Disadvantages of Linq

Advantages Quick turn around for development Queries can be dynamically Tables are automatically created into class Columns are automatically created into properties Relationship are automatically appeaded to classes Lambda expressions are awesome Data is easy to setup and use Disadvantages No clear outline for Tiers No good way of view permissions Small data sets will… Read More »