5

I have the following relation

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 using

SharedResource sharedResource = Get(shareKey)

And

sharedResource.PackageVersion == null. 

though VersionId is not null and

context.Configuration.LazyLoadingEnabled = false;

What do I have to do in order to load it

Bick
  • 17,833
  • 52
  • 146
  • 251

1 Answers1

6

LazyLoadingEnabled must be true, not false:

context.Configuration.LazyLoadingEnabled = true;

true is the default if you don't set LazyLoadingEnabled at all.

And the PackageVersion property must be virtual to enable lazy loading for this property.

Or you can include the property directly in the query:

SharedResource sharedResource = context.SharedResource
    .Include("PackageVersion")
    .SingleOrDefault(s => s.Id == shareKey);
Slauma
  • 175,098
  • 59
  • 401
  • 420