以前のリビジョンの文書です
<Nullable>enable</Nullable>
を削除
リビルドしても復旧せず。
パッケージを更新したらできるようになった。
解決方法は↓。
virtual ICollectionのため遅延バインディングとなっている。
そのためスキャフォールディングしたままだとICllectionはnullとなる。
Display ICollection in View
手動でコンテキストがICollcetionを読み込むのを待つように指示してやる。
コントローラーを以下のように変更する。
public async Task<IActionResult> Index() { return View(await _context.Article.ToListAsync()); }
↓
public async Task<IActionResult> Index() { return View(await _context.Article.Include(a => a.Comments).ToListAsync()); }
ビューでICollectionの関連データも読み取りれるようになる。
@foreach (var item_com in item.Comments) { <td> @Html.DisplayFor(modelItem => item_com.Body) </td> }
親ビューに下記コードを埋め込むとよびだせる。
親ビュー:Views\Shared\ControllerName\ParantView.cshtml
部分ビュー:Views\Shared\_PartialViewName.cshtml
<partial name="_PartialViewName" />
↓でも同じ
@await Html.PartialAsync("_PartialViewName")
なぜか「add-migration」ができない。
PM> add-migration [migration-name] Both Entity Framework 6 and Entity Framework Core are installed. The Entity Framework 6 tools are running. Use 'EntityFrameworkCore\Add-Migration' for Entity Framework Core. Your target project '[project-name]' doesn't reference EntityFramework. This package is required for the Entity Framework Core Tools to work. Ensure your target project is correct, install the package, and try again.
Add migration - Both Entity Framework Core and Entity Framework 6 are installed
よく見ると、書いてある通りにすればよかった。
PM> EntityFrameworkCore\Add-Migration AddAuthor ... Build started... Build succeeded. ...