Object structure - navigation property does not load

I have the following ratio

enter image description here

public partial class SharedResource : DomainEntity
{
    public System.Guid Id { get; set; }
    public System.Guid VersionId { get; set; }

    public virtual PackageVersion PackageVersion { get; set; } // tried it noth with and without virtual
}

Now I load SharedResource with

SharedResource sharedResource = Get(shareKey)

AND

sharedResource.PackageVersion == null. 

although VersionId is not null and

context.Configuration.LazyLoadingEnabled = false;

What do I need to do to download it

+5
source share
1 answer

LazyLoadingEnabledshould be true, not false:

context.Configuration.LazyLoadingEnabled = true;

trueis the default if you do not install at all LazyLoadingEnabled.

And the property PackageVersionmust be virtualin order to enable lazy loading for this property.

Or you can include the property directly in the request:

SharedResource sharedResource = context.SharedResource
    .Include("PackageVersion")
    .SingleOrDefault(s => s.Id == shareKey);
+6
source

All Articles