Show Menu
Cheatography

LINQ Cheat Sheet (DRAFT) by

LINQ: .NET Language Integrated Query

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Filters

 
Query Synax
Method Syntax
Purpose
Where
where n == value
.Where( (n) => n == "­val­ue")
Filters on condit­ional statement
OfType
-
.OfTyp­e<t­ype­Nam­e>
Filters by type

Joins

 
Query Synax
Method Syntax
Purpose
Join
from p in Parent
join c in Child on
p.Id equals c.Id
select new { p.Value, c.Chil­dValue }
Parent.Join(Child,
p => p.Id,
c => c.Id,
(p, c) => new { p, c })
Joins two collec­tions on condition
GroupJoin
from p in Parent
join c in Child on
p.Id equals c.Id into g
select new { Parent = p, Children = g }
Parent.GroupJoin(Child,
p => p.Id,
c => c.Id,
(p, c) => new { p, c })
Joins two collec­tions on condition, grouping by key value

Joins (copy)

 
Query Synax
Method Syntax
Purpose
Join
from p in Parent
join c in Child on
p.Id equals c.Id
select new { p.Value, c.Chil­dValue }
Parent.Join(Child,
p => p.Id,
c => c.Id,
(p, c) => new { p, c })
Joins two collec­tions on condition
GroupJoin
from p in Parent
join c in Child on
p.Id equals c.Id into g
select new { Parent = p, Children = g }
Parent.GroupJoin(Child,
p => p.Id,
c => c.Id,
(p, c) => new { p, c })
Joins two collec­tions on condition, grouping by key value