回答編集履歴

2

言語指定の誤りを修正

2022/08/16 13:36

投稿

jhashimoto
jhashimoto

スコア838

test CHANGED
@@ -1,41 +1,21 @@
1
1
  `SelectMany`の代わりにクエリ構文で`from`を使うと、シンプルに書けます。
2
2
 
3
-
4
-
5
- ```lang-c#
3
+ ```c#
6
-
7
4
  var query =
8
-
9
5
  from trader in traders
10
-
11
6
  from item in items
12
-
13
7
  where
14
-
15
8
  trader.Id == item.Id &&
16
-
17
9
  item.ExpiryDate > new DateTime(2010, 1, 1)
18
-
19
10
  select new {
20
-
21
11
  Id = trader.Id,
22
-
23
12
  CompanyNm = trader.CompanyNm,
24
-
25
13
  Address = trader.Address,
26
-
27
14
  Price = item.Price,
28
-
29
15
  ExpireDate = item.ExpiryDate
30
-
31
16
  };
32
17
 
33
-
34
-
35
18
  var result = query.ToList();
36
-
37
19
  ```
38
20
 
39
-
40
-
41
21
  [From … From … (SelectMany) - クエリ式の構文例:射影 - ADO.NET | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/framework/data/adonet/ef/language-reference/query-expression-syntax-examples-projection#from--from--selectmany)

1

ToListを追加

2021/10/21 23:50

投稿

jhashimoto
jhashimoto

スコア838

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```lang-c#
6
6
 
7
- var result =
7
+ var query =
8
8
 
9
9
  from trader in traders
10
10
 
@@ -32,6 +32,8 @@
32
32
 
33
33
 
34
34
 
35
+ var result = query.ToList();
36
+
35
37
  ```
36
38
 
37
39