Beruflich Dokumente
Kultur Dokumente
AND
Serve as a place for you to check details on LINQ stuff
o
1. Introduction
2. Motivation
3. Lambda expressions
4. LINQ
5. References
6. Q + maybe A
LINQ
Language Integrated
Query
Adds native data querying
abilities to .NET
Resembles SQL
High level -> performance
overhead
eg:
Lambda expressions
methods
5
Anonymous functions
Can be used in fancy ways
...But in reality (also called: this project) you will most likely
Expression lambdas
(int x, string s) => s.Length > x
Statement lambdas
delegate void TestDelegate(string s);
Assigning delegate
// c# 2.0
employee.SalaryChanged += delegate(Employee sender,
double amount)
{
Console.Writeline("changed");
}
// c# 3.0
employee.SalaryChanged += (sender, amount) =>
Console.Writeline("changed");
9
LINQ to objects
LINQ to XML
LINQ to SQL
LINQ to Sharepoint
10
Select
Where
SelectMany
Sum / Min / Max / Average
Aggregate
Join / GroupJoin
Take / TakeWhile
Skip / SkipWhile
OfType
Concat
OrderBy / ThenBy
Reverse
GroupBy
Distinct
Union / Intersect / Except
SequenceEqual
First / FirstOrDefault / Last
/ LastOrDefault
Single
ElementAt
Any / All / Contains
Count
11
1. Normal syntax
2. Lambda syntax
3. Where
4. Select
5. Order
6. Grouping
7. Set operators
8. Aggregate functions
9. Joins
12
SQL-like syntax
var productInfos =
from p in products
select p;
13
Lambda syntax:
customers.Where(c => c.City == "London");
14
Console.WriteLine("Short digits:");
foreach (var d in shortDigits)
{
Console.WriteLine("The word {0} is shorter than its value.", d);
}
}
15
16
17
18
19
20
Good reference:
http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx
22