LINQ Pocket Reference
LINQ Pocket Reference

By Joseph Albahari, Ben Albahari
Book Price: $14.99 USD
£8.99 GBP
PDF Price: $11.99

Cover | Table of Contents


Index


[ A ], 
[ B ], 
[ C ], 
[ D ], 
[ E ], 
[ F ], 
[ G ], 
[ H ], 
[ I ], 
[ J ], 
[ L ], 
[ M ], 
[ N ], 
[ O ], 
[ P ], 
[ Q ], 
[ R ], 
[ S ], 
[ T ], 
[ U ], 
[ V ], 
[ W ], 
[ X ], 
[ Y ], 


A[ Top ]
Add method, 128, 129
AddAfterSelf method, 130
AddBeforeSelf method, 130
AddFirst method, 129
Aggregate method, 107, 110
aggregation methods, 10, 107-111
      Aggregate, 107, 110
      Average, 107, 109
      Count, 107
      LongCount, 107
      Max, 107, 108
      Min, 107, 108
      Sum, 107, 109
All method, 111
Ancestors method, 126
AncestorsAndSelf method, 126
anonymous types, 30
Any method, 111
AsEnumerable method, 38-40, 101, 104
      advantage of using, 40
AsQueryable method, 33, 54, 95, 101, 104
associations (LINQ to SQL), 45-47
Attributes method, 128
Average method, 107, 109

B[ Top ]
building query expressions, 52-59
      AsQueryable method, 54
      delegates versus expression trees, 53-55
      expression trees, 55-59
            methods, 56

C[ Top ]
callbacks, 7
captured variables, 17
Cast method, 101-103
casting to nullable type, 134
chaining query operators, 4-6
Column attribute, 40
compiling expression trees, 53
composition strategies, 25-28
comprehension queries, 10-14
      from clause, 11
      group clause, 11
      iteration variable, 11, 12
      mixed syntax queries, 14
      OrderBy method, 12
      select clause, 11
      Select method, 12
      using System.Linq directive, 12
      Where method, 12
Concat method, 10, 100
Contains method, 111
continuations (query), 27
conversion methods, 15, 101-104
      AsEnumerable, 101, 104
      AsQueryable, 101, 104
      Cast, 101-103
      OfType, 101-103
      ToArray, 101, 103
      ToDictionary, 101, 103
      ToList, 101, 103
      ToLookup, 101, 103
correlated subqueries, 24, 69
Count method, 107
cross join, 77
      LINQ to SQL, 78
cross product, 77
custom equality comparers, 99

D[ Top ]
database schema, 37
DataContext class, 42-44
      multitier applications, 44
      ObjectTrackingEnabled, 43
      SubmitChanges method, 50
DataLoadOptions class, 48-49
      AssociateWith method, 49
      eager loading, 49
decorator sequences, 17
DefaultIfEmpty method, 105, 107
deferred execution, 15-21, 36
      with LINQ to SQL, 46
deferred loading with XML (streaming), 150
delegates versus expression trees, 53-55
Descendants method, 122
DescendantsAndSelf method, 122
Distinct method, 62, 66
document object model (DOM), 114

E[ Top ]
eager loading (LINQ to SQL), 49
Element method, 122
element operators, 104-107
      DefaultIfEmpty method, 105, 107
      ElementAt method, 105, 106
      ElementAtOrDefault method, 105
      First method, 104, 105
      FirstOrDefault method, 104, 105
      Last method, 104, 105
      LastOrDefault method, 104
      Single method, 104, 105
      SingleOrDefault method, 104, 105
element typing, 8
ElementAt method, 9, 105, 106
ElementAtOrDefault method, 105
elements, 1
      mapping input to output, 9
      projected, 5
Elements method, 122
ElementsAfterSelf method, 127
ElementsBeforeSelf method, 127
elementSelector, 97
Empty method, 112
entities (LINQ to SQL), 41
      associations, 45-47
      automatic entity generation, 45
EntityRef type, 47
EntitySet, 46
Enumerable class, 2, 4
      AsEnumerable method, 38-40
            advantage of using, 40
      query operators, 33
Enumerable.Where, 7
equi-join, 79
Except method, 100
expanding and flattening subsequences, 76
Expression class, 56
expression trees, 33, 36, 55-59
      compiling, 53
      methods, 56
      versus delegates, 53-55

F[ Top ]
filtering, 62-66
      Distinct method, 62, 66
      indexed, 64
      Skip method, 62, 65
      SkipWhile method, 62, 66
      Take method, 62, 65
      TakeWhile method, 62, 66
      Where method, 62-65
First method, 9, 104, 105
FirstAttribute method, 128
FirstNode, 123
FirstOrDefault method, 104, 105, 125
foreign keys, 50
from clause, 11, 67
      multiple from clauses, 73
Func signatures, 7
functional construction (LINQ to XML), 119-120

G[ Top ]
generation methods, 112-113
      Empty, 112
      Range, 113
      Repeat, 113
group clause, 97
GroupBy method, 95-99
      custom equality comparers, 99
      grouping by multiple keys, 99
      LINQ to SQL, 99
      overview, 96-98
GroupJoin method, 82, 88-91
      flat outer joins, 89
      joining with lookups, 90-91

H[ Top ]
HasAttributes method, 128
HasElements method, 122

I[ Top ]
IEnumerable interface, 1
implicit typing, 3, 30
indexed filtering, 64
interpreted queries, 33-40
      Enumerable.AsEnumerable, 38-40
            advantage of using, 40
      execution, 36-38
      how they work, 35-38
      IQueryable, 33
Intersect method, 100
into keyword, 27
IOrderedEnumerable, 94
IOrderedQueryable, 94
IQueryable, 2, 33
      implementations, 33
IsAfter method, 127
IsBefore method, 127
IsPrimaryKey property, 41
iteration variable, 11, 12
iterators, 18

J[ Top ]
Join method, 82-87
      joining with lookups, 90-91
      lambda syntax, 87
      multiple keys, 86
joining, 82-92
      cross join
            LINQ to SQL, 78
      equi-join, 79
      GroupJoin method, 82, 88-91
            flat outer joins, 89
            joining with lookups, 90-91
      Join method, 82-87
            joining with lookups, 90-91
            lambda syntax, 87
            multiple keys, 86
      LINQ to SQL, 69-71
      multiple keys, 86
      outer joins
            SelectMany method, 80-82
      SelectMany method, 77
      with lookups, 90-91

L[ Top ]
lambda expressions, 3
      composing, 6-9
      element typing, 8
      Func signatures, 7
lambda queries, 4-10
      chaining query operators, 4-6
      composing lambda expressions, 6-9
      natural ordering, 9
      syntax
            joining in, 87
            versus query syntax, 13
LambdaExpression class, 56
Last method, 9, 104, 105
LastAttribute method, 128
LastNode, 123
LastOrDefault method, 104
lazy evaluation, 15
let keyword, 32
LINQ to SQL, 33, 40-52
      associations, 45-47
      automatic entity generation, 45
      cross join, 78
      DataContext class, 42-44
            multitier applications, 44
            ObjectTrackingEnabled, 43
      DataLoadOptions class, 48-49
            AssociateWith method, 49
            eager loading, 49
      deferred execution, 47-48
      ElementAt method, 106
      entity classes, 40-42
      foreign keys, 50
      GroupBy method, 99
      interpreted queries (see interpreted queries)
      SelectMany method, 78-80
      SQL Server, 38
      subqueries and joins, 69-71
      updates, 50-52
      Where method, 64
LINQ to XML, 113-115
      architectural overview, 114
      automatic deep cloning, 121
      containership hierarchy, 115
      default namespaces, 143-145
      documents and declarations, 136-140
      functional construction, 119-120
            expression, 147
      inheritance hierarchy, 115
      instantiating, 118-121
      loading and parsing, 117
      namespaces
            attributes, 143
            elements, 143
      navigating and querying, 122-128
            attribute navigation, 128
            child node navigation, 122-126
            parent navigation, 126
            peer node navigation, 127
      overview, 115-118
      prefixes, 145-147
      projecting into, 147-152
            eliminating empty elements, 149
            streaming projection, 150
      recursive functions, 126
      retrieving elements, 123-125
      retrieving single element, 125
      saving and serializing, 118
      specifying content, 120-121
      specifying namespaces, 142-143
      transforming, 151-152
      updating, 128-132
            child nodes and attributes, 130
            removing sequence of nodes or attributes, 131
            simple value updates, 129
            through parent, 130-132
      working with values, 133-136
Load method, 117
local queries, 33
local sequence, 2
LongCount method, 107
lookups, joining with, 90-91

M[ Top ]
Max method, 107, 108
Min method, 107, 108
mixed syntax queries, 14
MoveNext, 11
multiple generators, 74
multiple keys, joining, 86

N[ Top ]
namespaces (XML), 141
NextNode method, 127
Nodes method, 123
NodesAfterSelf method, 127
NodesBeforeSelf method, 127
non-equi join, 78
nullable type, casting to, 134
NullReferenceException, 125, 135, 149

O[ Top ]
object hierarchies (projecting into), 68
object initializers, 30
ObjectTrackingEnabled, 43
OfType method, 101-103
OrderBy method, 4, 92-95, 97
      comprehension queries, 12
      lambda expressions, 7
OrderByDescending method, 92, 93
ordering, 92-95
      comparers and collations, 94
      IOrderedEnumerable, 94
      IOrderedQueryable, 94
      OrderBy method, 92-95
      OrderByDescending method, 92, 93
      Reverse method, 92
      ThenBy method, 92
      ThenByDescending method, 92, 93
outer iteration variables, 75-76
outer joins with GroupJoin, 88-90
outer joins with SelectMany method, 80-82
outer sequence
      join operators, 85
outer variable semantics, 17

P[ Top ]
Parent method, 126
Parse method, 117
predicate, 6
prefixes (XML), 141
PreviousNode method, 127
primary keys (LINQ to SQL), 41
progressively constructing queries, 5
projecting, 66-82
      comprehension syntax, 76-77
      concrete types, 71
      indexed projection, 68
      LINQ to SQL
            SelectMany method, 78-80
      outer iteration variables, 75-76
      outer joins with SelectMany method, 80-82
      Select (see Select method)
      SelectMany (see SelectMany method)
      subqueries and joins in LINQ to SQL, 69-71
      subqueries and object hierarchies, 68
projection strategies, 30-32

Q[ Top ]
quantifiers, 10, 111-112
      All method, 111
      Any method, 111
      Contains method, 111
      SequenceEqual method, 111
queries, 2
      building (see building query expressions)
      constructing progressively, 5
      interpreted (see interpreted queries)
      local (see local queries)
      mixed syntax, 14
      operators (see query operators)
      subqueries (see subqueries)
      wrapping, 28-29
query comprehension syntax, 4, 10
      (see also comprehension queries)
query continuation, 27, 88, 98
query operators, 2, 59-61
      categories, 59
      chaining, 4-6
      lambda expressions, 3, 7
      standard, 4
query processing, moving from database server to client, 40
query syntax (see comprehension queries)
Queryable class, 2, 33
      standard set of methods, 38

R[ Top ]
Range method, 113
range variable (see iteration variable)
refreshing objects (LINQ to SQL), 43
Remove method, 128, 130
      calling on sequence of nodes, 131
RemoveAll method, 129
RemoveAttributes method, 129
RemoveNodes method, 129
Repeat method, 113
Replace method, 128
ReplaceAll method, 129
ReplaceAttributes method, 129
ReplaceNodes method, 129
ReplaceWith method, 130
Reverse method, 9, 92

S[ Top ]
Save method, 118
Select method, 4, 11, 66, 84
      comprehension queries, 12
      concrete types, 71
      indexed projection, 68
      lambda expressions, 7
      LINQ to SQL, 69-71
      ordering, 9
      subqueries and object hierarchies, 68
SelectMany method, 66, 72-82, 84
      comprehension syntax, 76-77
      joining, 77
      LINQ to SQL, 78-80
      outer iteration variables, 75-76
      outer joins, 80
      overview, 73-75
      versus Join, 85
SequenceEqual method, 111
sequences, 1
set operators, 100-101
      Concat method, 100
      Except method, 100
      Intersect method, 100
      Union method, 100
SetAttributeValue method, 129
SetElementValue method, 128, 129
SetValue method, 128, 133
Single method, 9, 42, 104, 105
SingleOrDefault method, 104, 105
Skip method, 9, 62, 65
SkipWhile method, 62, 66
SQL
      AVG (), 107
      COUNT( ), 107
      CROSS JOIN, 66
      EXCEPT, 100
      GROUP BY, 95
      INNER JOIN, 66, 82
      LEFT OUTER JOIN, 66, 82
      MAX( ), 107
      MIN( ), 107
      NOT IN, 62
      ORDER BY, 92, 104
      ORDER BY - DESC, 104
      SELECT, 66
      SELECT DISTINCT, 62
      SELECT TOP 1, 104
      subqueries, 13
      SUM( ), 107
      UNION, 100
      UNION ALL, 100
      WHERE, 62, 111
      WHERE - IN, 100, 111
      WHERE ROW_NUMBER, 62
      (see also LINQ to SQL)
SQL Server, 2, 34, 38, 39
      auto-incrementing field, 51
      ROW_NUMBER function, 65
SQL syntax versus LINQ query syntax, 13
SqlMetal, 45, 51
standard query operators, 59
subqueries, 22-25
      correlated, 24, 69
      deferred execution of, 25
      LINQ to SQL, 69-71
      Select method, 68
subsequences, expanding and flattening, 76
Sum method, 107, 109
System.Core, 1
System.Linq, 1
      standard query operators, 2
System.Linq.Expressions, 56

T[ Top ]
Table attribute, 40
Take method, 9, 62, 65
TakeWhile method, 62, 66
TextWriter, 118
ThenBy method, 92
ThenByDescending method, 92, 93
ToArray method, 40, 101, 103
ToDictionary method, 101, 103
ToList method, 40, 101, 103
ToLookup method, 101, 103
ToString method, 118, 121

U[ Top ]
Union method, 10, 100
updates, LINQ to SQL, 50
using System.Linq directive, 12

V[ Top ]
var keyword, 3, 31
Visual Studio, 45, 51

W[ Top ]
Where method, 2, 3, 4, 62-65
      comprehension queries, 12
      indexed filtering, 64
      lambda expressions, 6
      LINQ to SQL, 64
      ordering, 9
wrapping queries, 28-29

X[ Top ]
XAttribute, 116
      casting to nullable type, 134
      constructing, 118
      Remove method, 130
      SetValue method, 128
      Value property, 133-136
            getting values, 133-135
            setting values, 133
XComment, 116, 120
XContainer, 122
      Add method, 129
      AddFirst method, 129
      child nodes, 116
      decisions, 120
      Descendants method, 122
      Element method, 122
      Elements method, 122
      RemoveNodes method, 129
      ReplaceNodes method, 129
      ToString, 121
XDeclaration, 136, 137
      absence, 139
      XNode, 138
XDocument, 136-138
      accepted content, 136
      constructs, 137
      Root property, 138
      XElement, 137
XDocumentType, 137
X-DOM (see LINQ to XML)
XElement
      AncestorsAndSelf method, 126
      Attribute method, 128
      Attributes method, 128
      casting to nullable type, 134
      constructing, 118, 143
      DescendantsAndSelf method, 122
      FirstAttribute method, 128
      HasAttributes method, 128
      HasElements method, 122
      LastAttribute method, 128
      Load method, 117
      namespaces, 143
      Parse method, 117
      RemoveAll method, 129
      RemoveAttributes method, 129
      ReplaceAll method, 129
      ReplaceAttributes method, 129
      SetAttributeValue method, 129
      SetElementValue method, 129
      SetValue method, 128
      Value property, 133-136
            getting values, 133-135
            setting values, 133
      XDocument, 137
XML
      declarations, 139-140
      names and namespaces, 140-147
            default namespaces, 143-145
            prefixes, 145-147
            specifying namespaces in X-DOM, 142-143
      serialization, 139
      (see also LINQ to XML)
XmlWriter, 118
XName, 142, 143
      + operator, 143
XNamespace, 142
XNode, 116, 122, 138
      AddAfterSelf method, 130
      AddBeforeSelf method, 130
      Ancestors method, 126
      child nodes, 116
      ElementsAfterSelf method, 127
      ElementsBeforeSelf method, 127
      IsAfter method, 127
      IsBefore method, 127
      NextNode method, 127
      NodesAfterSelf method, 127
      NodesBeforeSelf method, 127
      Parent method, 126
      PreviousNode method, 127
      Remove method, 130
      ReplaceWith method, 130
XObject, 116
      Document property, 138
XProcessingInstruction, 137
XStreamingElement, 151
XText
      automatic concatenation, 136
      values and mixed content nodes, 135

Y[ Top ]
yield return, 19


Return to LINQ Pocket Reference