I'm trying to understand why, sometimes, my sub-objects disappear.
In my List view, I have the standard
<% foreach (var item in Model)
and when I inspect the item and the model, I can see that item.Map has a couple of elements.
In fact, in my List view I can do:
<% foreach (var map in item.Map)
<% Html.RenderPartial("MapView", map); %>
and MapView can access and display all the properties. I'm including the sub-objects with:
list = from item in _entities.DataTable
.Include("LookupTable1")
.Include("Map")
.Include("Map.LookupTable2") select item;
return View("List", list);
But if I try to do:
<%= Html.Encode(item.Map.FirstOrDefault().Field)%>
I get a null pointer exception, and item.Map has 0 elements.
Can anyone explain why this is happening?