25. •
class Foo : IQueryable
{
public Type ElementType
{ get { throw new NotImplementedException(); } }
public Expression Expression
{ get { throw new NotImplementedException(); } }
public IQueryProvider Provider
{ get { throw new NotImplementedException(); } }
public IEnumerator GetEnumerator()
{ throw new NotImplementedException(); }
}
ソースコード
参照
27. •
var data = new EmployeeModel();
data.Database.Log = message => Debug.Write(message);
var sequence1 = data.Employees;
var sequence2 = sequence1.Where (employee => employee.Name.Contains("川"));
var sequence3 = sequence2.Select (
employee => new { 番号 = employee.Number, 名前 = employee.Name });
Debug.WriteLine("■ ラムダ式サンプル: 出力開始 ■");
foreach (var employee in sequence3)
Console.WriteLine("{0}: {1}", employee.番号, employee.名前);
Debug.WriteLine("■ ラムダ式サンプル: 出力終了 ■");
ソースコード
参照
28. •
SELECT
[Extent1].[Number] AS [Number],
[Extent1].[Name] AS [Name]
FROM [dbo].[Employee] AS [Extent1]
WHERE [Extent1].[Name] LIKE N'%川%'
SELECT
[Extent1].[Number] AS [Number],
[Extent1].[Name] AS [Name],
[Extent1].[DepartmentID] AS [DepartmentID],
[Extent1].[EmailAddress] AS [EmailAddress]
FROM [dbo].[Employee] AS [Extent1]
•
29. •
public static class Queryable
{
public static IQueryable<T> Where<T>(this IQueryable<T> source,
Expression<Func<T, bool>> predicate);
}
public static class Enumerable
{
public static IEnumerable<T> Where<T>(this IEnumerable<T> source,
Func<T, int, bool> predicate);
}
•
36. •
ソースコード
参照
// メソッド構文
var fizzBuzzs = Enumerable.Range(1, 50).Select(FizzBuzz);
// クエリー構文
var fizzBuzzs = from number in Enumerable.Range(1, 50)
select FizzBuzz(number);
37. •
ソースコード
参照
// メソッド構文
var numbers = Enumerable.Range(1, 9)
.SelectMany(x => Enumerable.Range(1, 9),
(x, y) => string.Format("{0}x{1}={2}", x, y, x * y));
// クエリー構文
var numbers = from x in Enumerable.Range(1, 9)
from y in Enumerable.Range(1, 9)
select string.Format("{0}x{1}={2}", x, y, x * y);
38. •
ソースコード
参照
// メソッド構文
var numbers = new[] { 2, 6, 1, 3, -7, 1, -6, 0, -3 }
.Where(number => number % 2 == 0);
// クエリー構文
var numbers = from number in new[] { 2, 6, 1, 3, -7, 1, -6, 0, -3 }
where number % 2 == 0
select number;
39. •
ソースコード
参照
// メソッド構文
var orderedPeople = people.OrderByDescending(person => person.Age)
.ThenBy(person => person.Name);
// クエリー構文
var orderedPeople = from person in people
orderby person.Age descending, person.Name
select person;
40. •
ソースコード
参照
// メソッド構文
var collection = Enumerable.Range(1, 10)
.Select(x => x * x)
.Where(x => x > 50);
// クエリー構文
var collection = from n in Enumerable.Range(1, 10)
select n * n into m
where m > 50
select m;
41. •
ソースコード
参照
// メソッド構文
var collection = books.GroupBy(book => book.Genre);
// クエリー構文
var collection = from book in books
group book by book.Genre;
•
• https://msdn.microsoft.com/ja-jp/library/bb546133.aspx
42. •
ソースコード
参照
// メソッド構文
var collection = bookGenres.Join(books,
bookGenre => bookGenre.Genre,
book => book.Genre,
(bookGenre, book) =>
new { Genre = bookGenre.Name, Title = book.Title });
// クエリー構文
var collection = from bookGenre in bookGenres
join book in books on bookGenre.Genre equals book.Genre
select new { Genre = bookGenre.Name, Title = book.Title };
43. •
ソースコード
参照
var numbers1 = new int[] { 10, 20, 30, 40, 50 };
var numbers2 = new int[] { 1, 2, 3 };
// メソッド構文
var collection = numbers1.Zip(
numbers2,
(number1, number2) => number1 + number2
);