Transcript Slajd 1

Zapytania ( 3.0 )
•
wyrażenia zapytaniowe - querry expressions
•
przestrzeń nazw LINQ - Language-Integrated Query
•
3 etapy :
1. określenie źródła danych,
2. utworzenie zapytania,
3. wykonanie zapytania.
class IntroToLINQ
{ static void Main()
{
int[] numbers =
//
1. Data source.
new int[7] { 0, 1, 2, 3, 4, 5, 6 };
//
2. Query creation.
var numQuery =
from num in numbers
where (num % 2) == 0
select num;
// 3. Query execution.
foreach (int num in numQuery)
{
Console.Write("{0} ", num);
}}}
• technologie LINQ
•
Linq to Objects
•
Linq to DataSet
IEnumerable
•
Linq to SQL
IEnumerable< >
•
Linq to XML
•
Linq to own sources
IQueryable< > , IQueryProvider
•
słowa kluczowe
from
// źródło danych
where
// filtrowanie danych
select
// pobieranie danych
join
// łączenie danych
orderby
// sortowanie danych
ascending
// rosnąco
descending
// malejąco
let
// nadanie wartości
group
// grupowanie danych
into
// kontynuacja zapytania
• funkcje rozszerzające IEnumerable, IEnumerable< >
Select, SelectMany
// pobieranie danych
OrderBy, ThenBy, OrderByDescending,
ThenByDescending, Reverse
// sortowanie
Where
// filtrowanie
Aggregate, Average, Count, LongCount,
Max, Min, Sum
// artymetyczne
Cast, OfType, ToArray, ToDictionary, ToList,
ToLookup, ToSequence
// konwersja
Element, DefaultIfEmpty, ElementAt,
ElementAtOrDefault, First, FirstOrDefault,
Last, LastOrDefault,
Single, SingleOrDefault // pobieranie elementu
EqualAll
// porównywanie
Empty, Range, Repeat
// tworzenie
GruopBy
// grupowanie
GroupJoin, Join
// łączenie
Skip, SkipWhile,
// pomijanie
Take, TakeWhile
// wybór
All, Any, Contains
// kwantyfikatory
Concat, Distinct, Exept,
Intersection, Union
// operacje na zbiorach