Skip to content

ILazyLoader - information about foreign key property and not tracking #5257

@tNRevan

Description

@tNRevan

Type of issue

Missing information

Description

I think you should add context to the "Lazy loading without proxies" category that a foreign key property is required within the entity if it is accessed in not tracked entity.

Example:

var postNoTracking = context.Posts.AsNoTracking().First();
postNoTracking.Blog.Name <- throws "System.InvalidOperationException: 'The navigation 'Post.Blog' cannot be loaded because one or more of the key or foreign key properties are shadow properties and the entity is not being tracked. Relationships using shadow values can only be loaded for tracked entities.'"

When I add

public int BlogId { get; set; }

it works.

I think you should clarify this in the text as a warning.

Page URL

https://learn.microsoft.com/en-us/ef/core/querying/related-data/lazy

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/querying/related-data/lazy.md

Document Version Independent Id

7c665098-afcc-1ba0-d6a2-0262ae921575

Platform Id

42a58a81-0fe0-72ab-50b8-4bbbeb5acf76

Article author

@roji

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions