I have tried to get the Related Entities in .Net Core in a scaffolding context.
I am building a Details page in MVC that is being scaffolded. I need the Properties and Navigations. All the relevant properties are being shown, however, only the non-ICollection navigation properties are shown from .Navigations.
The object being loaded is Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.ModelMetaData
foreach (var property in Model.ModelMetadata.Properties)
{
if (property.Scaffold && !property.IsPrimaryKey && !property.IsForeignKey)
{
<dt>
@@Html.DisplayNameFor(model => model.@GetValueExpression(property))
</dt>
<dd>
@@Html.DisplayFor(model => model.@GetValueExpression(property))
</dd>
}
}
foreach (var navigation in Model.ModelMetadata.Navigations)
{
<dt>
@@Html.DisplayNameFor(model => model.@GetValueExpression(navigation))
</dt>
<dd>
<a asp-area="" @GetNavigationLinkExpression(navigation)>@@Html.DisplayFor(model => model.@GetValueExpression(navigation).@navigation.DisplayPropertyName)</a>
</dd>
}
My model is as such... and the ModelMetaData can only navigate through the second and skips the first. Where can I get access to the first property here so that I can template it?
public virtual ICollection<SomeModel> CollectionNavigationProperty1 { get; set; }
public virtual AnotherSomeModel NavigationProperty1 { get; set; }