I have the following relation

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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With