質問編集履歴

5

修正

2021/09/10 11:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -8,9 +8,17 @@
8
8
 
9
9
 
10
10
 
11
+ 9/10 20:42 コード修正しました。
12
+
11
13
  ```C#
12
14
 
15
+ using System.Collections.Generic;
16
+
17
+ using System.Linq;
18
+
19
+
20
+
13
- public class Base() {
21
+ public class Base {
14
22
 
15
23
  public long Id { get; set; }
16
24
 
@@ -24,7 +32,7 @@
24
32
 
25
33
 
26
34
 
27
- public class Sub() {
35
+ public class Sub {
28
36
 
29
37
  public long Id { get; set; }
30
38
 
@@ -40,29 +48,33 @@
40
48
 
41
49
 
42
50
 
43
- public void Test() {
51
+ public class Test {
44
52
 
45
- IList<Base> bases = new List<Base>() {
53
+ public static void Main() {
46
54
 
47
- new Base() { Id = 1, Name = "a", Subs = null },
55
+ IList<Base> bases = new List<Base>() {
48
56
 
49
- new Base() { Id = 2, Name = "b", Subs = null }
57
+ new Base() { Id = 1, Name = "a", Subs = null },
50
58
 
59
+ new Base() { Id = 2, Name = "b", Subs = null }
60
+
51
- };
61
+ };
52
62
 
53
63
 
54
64
 
55
- // 平坦化するデータがない時はnullを返したい。
65
+ // 平坦化するデータがない時はnullを返したい。
56
66
 
57
- IList<Base> bases2 = bases
67
+ var bases2 = bases
58
68
 
59
- .SelectMany(e => e.Subs.DefaultIfEmpty(), (e, e2) => e.Subs != null ? new Base() {
69
+ .SelectMany(e => e.Subs.DefaultIfEmpty(), (e, e2) => e.Subs != null ? new {
60
70
 
61
- Id = e.Id,
71
+ Id = e.Id,
62
72
 
63
- SubName = e2.Name
73
+ SubName = e2.Name
64
74
 
65
- } : null);
75
+ } : null);
76
+
77
+ }
66
78
 
67
79
  }
68
80
 

4

2021/09/10 11:44

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  public void Test() {
44
44
 
45
- IList<Base> = new List<Base>() {
45
+ IList<Base> bases = new List<Base>() {
46
46
 
47
47
  new Base() { Id = 1, Name = "a", Subs = null },
48
48
 

3

修正

2021/09/10 11:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- public IList<Sub> Subs { get; set; }
21
+ public virtual IList<Sub> Subs { get; set; }
22
22
 
23
23
  }
24
24
 
@@ -31,6 +31,10 @@
31
31
  public string Name { get; set; }
32
32
 
33
33
  public long BaseId { get; set; }
34
+
35
+
36
+
37
+ public virtual Base Base { get; set; }
34
38
 
35
39
  }
36
40
 

2

修正

2021/09/10 09:45

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  new Base() { Id = 1, Name = "a", Subs = null },
44
44
 
45
- new Base() { Id = 2, Name = "b", Subs = null },
45
+ new Base() { Id = 2, Name = "b", Subs = null }
46
46
 
47
47
  };
48
48
 

1

修正

2021/09/10 09:45

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  Id = e.Id,
58
58
 
59
- SubName = e2.SubName
59
+ SubName = e2.Name
60
60
 
61
61
  } : null);
62
62