0

我正在使用 .NET 3.5,但无法自动加载实体引用。理想情况下,它有时似乎有效,我想要类似的东西

Dim relocations = ctx.EmployeeRelocations.Where(Function(o) o.Employee.EmployeeNumber = employeeNumber).ToList()
If Not relocations.Where(Function(o) o.ValidTerritory.Territory = territory).Any() Then

其中 ValidTerritory 是重定位中的引用类型。但相反,当我尝试这样做时,我得到 Object Not set to an instance... for o.ValidTerritory。所以,我可以做到这一点,一切正常:

If Not relocations.Where(Function(o)
                             o.ValidTerritoryReference.Load()
                             Return o.ValidTerritory.Territory = territory
                         End Function).Any() Then

从理论上讲,发生的事情是有道理的,但我不明白为什么我需要显式加载以及为什么这种行为似乎来来去去(也就是说,它有时会很好地加载引用而没有显式加载)。

4

1 回答 1

1

尝试使用Include来获取该数据:

relocations.Include("ValidTerritory").Where(Function(o) o.ValidTerritory.Territory = territory).Any()
于 2012-04-12T20:08:09.050 回答