I’m using .NET 3.5 and I’m having trouble loading the Entity References automatically. Ideally, and it seems to work sometimes, I would like something like
Dim relocations = ctx.EmployeeRelocations.Where(Function(o) o.Employee.EmployeeNumber = employeeNumber).ToList()
If Not relocations.Where(Function(o) o.ValidTerritory.Territory = territory).Any() Then
where ValidTerritory is a reference type in relocations. But instead, when I try that, I get Object Not set to an instance… for o.ValidTerritory. So, I can do this and everything works fine:
If Not relocations.Where(Function(o)
o.ValidTerritoryReference.Load()
Return o.ValidTerritory.Territory = territory
End Function).Any() Then
In theory, it makes sense what’s happening, but I don’t understand why I need the explicit Load and why this behavior seems to come and go (that is, it sometimes loads the references fine with no explicit load).
Try using
Includeto get that data: