Standard Query Operators
The LINQ standard query operators can be applied to any .NET array or collection that implements the IEnumerable or IEnumerable<T/> interfaces
These operators are method that provide querying capabilities.
There are two sets of query operators:
IEnumerable<T>
IQueryable<T>
These extension methods can be called by using either static method syntax or instance method syntax
Aggregate | |
All | |
Any | |
AsEnumerable | Converting |
Average | |
Cast | |
Concat | |
Contains | |
Count | |
DefaultIfEmpty | |
Distinct | |
ElementAt | |
ElementAtOrDefault | |
Empty | |
Except | |
First | |
FirstOrDefault | |
GroupBy | |
GroupJoin | |
Intersect | |
Join | |
Last | |
LastOrDefault | |
LogCount | |
LongCount | |
Max | |
Min | |
OfType | Converting |
OrderBy | |
OrderByDescending | |
Range | |
Repeat | |
Reverse | |
Select | |
SelectMany | |
SequenceEqual | |
Single | |
SingleOrDefault | |
Skip | |
SkipWhile | |
Sum | |
Take | |
TakeWhile | |
ThenBy | |
ThenByDescending | |
ToArray | |
ToDictionary | |
ToList | |
ToLookup | |
Union | |
Where |
LINQ to Objects
This refers to the use of LINQ queries with any IEnumerable or IEnumerable<T> collection directly.
You can also use LINQ to query any enumerable collections such as List<T>, Array or Dictionary<TKey, TValue>
These queries look similar to SQL queries but they are very different
LINQ brings an element of functional programming into C#
It adds various new keywords for building query expressions
The LINQ query expressions are translated into a chain of extension method calls or standard query operators.
System.Linq
var linq_query = from x in myobjects
where x.Name = "Simon"
orderby x.Age
select new { Name = x.Name, Age = x.Age }
foreach (var item in linq_query)
{
System.Console.Writeline("{0}. {1}, item.Name, item.Age);
}
Provide a list of standard LINQ query operators
Where - filters the data
OrderBy - sorts the dataset
Select - specific columns in dataset
Where
subset = myobjects.Where(o => o.Value == false)
OrderBy
subset = myobjects.OrderBy(o => o.Length)
Select
subset = myobjects.Select(o => new {o.Name, o.Value};
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext