What is difference between Select and SelectMany in LINQ?

Select and SelectMany are projection operators. Select operator is used to select value from a collection and SelectMany operator is used to select values from a collection of collection i.e. nested collection. Select operator produce one result value for every source value while SelectMany produce a single result that contains… Continue reading

What are advantages of using LINQ on DataSet?

LINQ to DataSet is useful to run strongly typed queries on multiple datasets. SQL query is able to populate the dataset from the database but not able to retrieve a particular value from the dataset. LINQ is the best way to do further data manipulation operations (like searching, filtering, sorting)… Continue reading

When to use Single, SingleOrDefault, First and FirstOrDefault?

You should take care of following points while choosing Single, SingleOrDefault, First and FirstOrDefault. When you want an exception to be thrown if the result set contains many records, use Single or SingleOrDefault. When you want a default value is returned if the result set contains no record, use SingleOrDefault…. Continue reading

What is difference among Single, SingleOrDefault, First and FirstOrDefault?

Single – It returns a single specific element from a collection of elements if element match found. An exception is thrown, if none or more than one match found for that element in the collection. SingleOrDefault – It returns a single specific element from a collection of elements if element… Continue reading

What are element operators?

Element operators return a single element or a specific element from a collection. The elements operators are Single, SingleOrDefault, First, FirstOrDefault, Last, LastOrDefault. List < int > data = new List < int > { 10, 20, 30, 40, 50 }; //Try to get element at specified position Console.WriteLine(data.ElementAt(1)); //result:20… Continue reading

What are aggregate operators?

Aggregate operators perform calculations on a set of values and return a single value. The aggregate operators are Average, Count, Max, Min, and Sum. List < int > data = new List < int > { 10, 20, 30, 40, 50 }; //Sum of numbers Console.WriteLine(data.Sum()); //result:150 //Average of numbers… Continue reading

What are different types of operators in LINQ?

LINQ provides you various operators to write a LINQ query. Various types of operators are given below:  Operator Type  Operator Name  Aggregate  Aggregate, Average, Count, LongCount, Max, Min, Sum  Concatenation  Concat  Conversions  Cast, OfType, ToList, ToArray, ToLookup, ToDictionary, AsEnumerable  Element  Single, SingleOrDefault, First, FirstOrDefault, Last, LastOrDefault, ElementAt, ElementAtOrDefault  Equality  SequenceEqual… Continue reading