2
剛開始與EF一起工作,無法弄清楚我是否錯誤地思考或者我只是想念一些簡單的東西。在MVC中導航多個關係EF
我試圖讓機構,SendRule和和鏈接到SendRule在一個窗口CrimeType信息。
在控制器,我傳遞給像這樣的數據模型:
var institution = await _context.Institution
.Include(i => i.Rules)
.ThenInclude(r => r.SendRule)
.ThenInclude(c => c.CategoriesToSend)
.ThenInclude(cr => cr.CrimeType)
.AsNoTracking()
.SingleOrDefaultAsync(m => m.InstitutionID == id);
,並考慮,我一切都顯示,像這樣:
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<table class="table">
<tr>
<th>Rule Name</th>
<th>Cron</th>
<th>Categories</th>
</tr>
@foreach (var item in Model.Rules)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.SendRule.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.SendRule.Cron)
</td>
<td>
@foreach (var item2 in Model.Rules)
{
@Html.DisplayFor(modelThing => item2.SendRule.CategoriesToSend)
}
</td>
</tr>
}
</table>
但從item2.SendRule.CategoriesToSend我不能導航到CrimeType。這是因爲它的多對一關係嗎?我錯過了什麼?