public async Task Index()
{
return View(await _context.Article.ToListAsync());
}
↓
public async Task Index()
{
return View(await _context.Article.Include(a => a.Comments).ToListAsync());
}
ビューでICollectionの関連データも読み取りれるようになる。
@foreach (var item_com in item.Comments)
{
@Html.DisplayFor(modelItem => item_com.Body)
}
====== 部分ビュー ======
親ビューに下記コードを埋め込むとよびだせる。
親ビュー:Views\Shared\ControllerName\ParantView.cshtml
部分ビュー:Views\Shared\_PartialViewName.cshtml
↓でも同じ
@await Html.PartialAsync("_PartialViewName")
====== Both Entity Framework 6 and Entity Framework Core are installed ======
なぜか「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.
[[https://entityframeworkcore.com/knowledge-base/51671741/add-migration---both-entity-framework-core-and-entity-framework-6-are-installed|Add migration - Both Entity Framework Core and Entity Framework 6 are installed]]
よく見ると、書いてある通りにすればよかった。
PM> EntityFrameworkCore\Add-Migration AddAuthor
...
Build started...
Build succeeded.
...
PM> entityframeworkcore\update-database
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Update-Database' for Entity Framework 6.
Build started...
Build succeeded.
自動マイグレーションは廃止されていた
PM> entityframeworkcore\Enable-Migrations –EnableAutomaticMigrations
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Enable-Migrations' for Entity Framework 6.
Enable-Migrations is obsolete. Use Add-Migration to start using Migrations.