score:1

Based on the wording you used, it appears that you expect the PriceLevel property to be null when not using lazy loading.

There are some cases i can think of, in which this expectation would not be met.

The first case would be if you are loading the data in a eager way. Which would be explicitly using Include(). This behaviour is also called eager loading. Since eager loading does load everything it is allowed to, it does not require you to enumerate the collection by calling ToArray() or ToList() or other methods that trigger enumeration. Every property which is not lazy will be loaded, that includes all its value type properties and non-lazy properties.

Your code does not indicate this, however the property would still not be null if you did this on the same DbContext derived instance before executing the code you displayed. This would happen whenever the entity in question already resides cached in your DbContext.

The same would be true if you had loaded that entity explicitly by calling Load() or if it had been returned from some other previous query.

In order to verify whether this is the case or not you can use the AsNoTracking() extension method. Entities which are not tracked will, among other effects, not be linked with each other.


Related Articles