回答編集履歴

1

追記

2020/12/08 00:43

投稿

退会済みユーザー
test CHANGED
@@ -3,3 +3,61 @@
3
3
 
4
4
 
5
5
  それでエラーになりませんか? 前のスレッドのやり取りを見てない?
6
+
7
+
8
+
9
+ **【2020/12/8 9:40 追記】**
10
+
11
+
12
+
13
+ コンパイルエラーだったんですね。見落としてました。
14
+
15
+
16
+
17
+ > 型 'System.Collections.Generic.List<System.Linq.IGrouping<string, SampleProject.Models.BList>>' を 'System.Collections.Generic.IEnumerable<SampleProject.Models.BList>' に暗黙的に変換できません。明示的な変換が存在します (キャストが不足していないかどうかを確認してください)
18
+
19
+
20
+
21
+ そのエラーは、エラーメッセージが言うように SampleViewModel クラスの BLists プロパティの型 IEnumerable<BList> を System.Collections.Generic.List<System.Linq.IGrouping<string, SampleProject.Models.BList>> に変更すれば出なくなります。
22
+
23
+
24
+
25
+ それでコンパイルは通るはずですが、相手が SQL Server でしょうから、今度は実行時に _context.BLists.GroupBy(x => x.Kind) のところでそれを SQL Server に発行するための SQL 文に変換できないということで、"Client side GroupBy is not supported" というエラーになると思います。
26
+
27
+
28
+
29
+ 最初に回答したのはそのことを言ってます。解決策は前のスレッド [https://teratail.com/questions/307318](https://teratail.com/questions/307318) を見てください。
30
+
31
+
32
+
33
+
34
+
35
+ > SampleViewModelのView側1行目にあるModelのImport部分も
36
+
37
+
38
+
39
+ > @model DBAccessSample.Models.SampleViewModel
40
+
41
+
42
+
43
+ > ではなく
44
+
45
+
46
+
47
+ > @model IEnumerable<IGrouping <string,SampleProject.Models.SampleViewModel>>
48
+
49
+
50
+
51
+ > にするべきなのでしょうが
52
+
53
+
54
+
55
+ そこは、
56
+
57
+
58
+
59
+ > 実現したいことは、AListと、BListをGroupByしたもの、2つのModelをViewModelとして1つのViewに表示させることです。
60
+
61
+
62
+
63
+ という目的を果たすためにはそのままにしておかないとダメです。View の中で、controller から受け取った SampleViewModel の ALists, BLists プロパティで「AListと、BListをGroupByしたもの」を取得して表示するということになります。