dotnet / dotnet/EntityFramework.Docs

ILazyLoader - information about foreign key property and not tracking

Open
#5,257 0 comments 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-change-tracking
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.