I have the following code which should bind some data to a gridview but its not working.
THe district manager object has a Brand.
As you can see in the screenshot the brand is correctly filled in with data.
private void LoadData()
{
List<DealerDistrictManager> listDealerDistrictManager = DistrictManagerBL.GetAllDealersWithDistrictManagers();
DistrictManagersGrid.DataSource = listDealerDistrictManager;
DistrictManagersGrid.DataBind();
<asp:BoundColumn DataField="DistrictManagerId" Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Brand.Name" meta:resourcekey="BrandHeader"></asp:BoundColumn>
public class DealerDistrictManager
{
public int DistrictManagerId { get; set; }
public string Nuteres { get; set; }
public string DealerNumber { get; set; }
public virtual Brand Brand { get; set; }
public int DistrictNumber { get; set; }
public string Name { get; set; }
}
public class Brand
{
public int BrandId { get; set; }
public string Name { get; set; }
}
Update1
public List<DealerDistrictManager> GetAllDealersWithDistrictManagers()
{
return (from d in _context.Dealers
from m in _context.DistrictManagers
where d.Nuteres == m.DealerNuteres
select new DealerDistrictManager
{
DistrictManagerId= m.DistrictManagerId,
Nuteres = d.Nuteres,
DealerNumber = d.DealerNumber,
Brand = m.Brand,
DistrictNumber = m.DistrictNumber,
Name = m.Name
}).ToList<DealerDistrictManager>();
}

This post also speaks about the same / similar problem. Where it “randomly” occurs. The solution that the questioner found was to use:
The post mentioned has a lot of answers (including an accepted one) that will clarify a lot I presume.