dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.62k stars 1.96k forks source link

Need example of loading a single navigation property, not collection #2068

Open rgamage opened 4 years ago

rgamage commented 4 years ago

The example of loading a collection after getting and inital object is great (Querying Related Entities), but what if you want a related single object, not a collection? I can't figure out the syntax for that case.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ghost commented 4 years ago

Agree, It should be added to the documentation. In case you still need it it's like this:

context.Entry(blog).Reference(p => p.SingleNavigationPropertyOfBlog).Load()