string[] currentVideoGames = {"Morrowind",
"BioShock", "Half Life 2"};
// Build a
query expression using extension methods
// granted
to the Array via the Enumerable type.
Sorting Results:
from
game in currentVideGames
where
game.length > 5
descending
select
game
Grouping Results:
from
game in currentVideGames
where
game.length > 5
group
game by game into gamegroup
select gamegroups;
now get group list;
from
gamegroup in gamegroups
select
new {gamegroup.key, gamegroup.Count() }
Outer Join:
var data = from
c in customers
join
o in ( from orderInJan97
in orders
where
orderInJan97.OrderDate.Value.Year == 1997
&&
orderInJan97.OrderDate.Value.Month == 1
select
orderInJan97
)
on
c.CustomerID equals o.CustomerID into groupOrders
select
new { c.CompanyName,OrderTotal = groupOrders.Count() };
Partioning and Paging:
var data =
( from c in customers
select c).Take(10);
var data =
(from c in customers
select c). Skip(30). Take(10);
Nested Queries:
only having
length 5 - 10
(from
game in currentVideGames
where
game.length > 5
select
game
).Except
(
from
game
where
game.length >10
select game
);