© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
47 replies
Lounder

✅ EF Core navigational properties

This works fine (no navigational property to Business):
class Business
- ...
- Address Address { get; set; }

class Address
- ...
class Business
- ...
- Address Address { get; set; }

class Address
- ...

This causes an error:
class Business
- ...
- Address Address { get; set; }

class Address
- ...
- Business { get; set; }
class Business
- ...
- Address Address { get; set; }

class Address
- ...
- Business { get; set; }

InvalidOperationException: The value of 'Address.Id' is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known
InvalidOperationException: The value of 'Address.Id' is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known

Initialization code:
            var address = new Address
            {
                Street = "SName",
                City = "CName",
            };

            await dbContext.Addresses.AddAsync(address);
            var address = new Address
            {
                Street = "SName",
                City = "CName",
            };

            await dbContext.Addresses.AddAsync(address);

How can I make this work while also keeping Address' nav property to Business?
Please @ me so I respond immediately
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Calculated Properties with EF Core
C#CC# / help
2y ago
EF Core - Intermediate table or Navigation Properties?
C#CC# / help
17mo ago
EF Core
C#CC# / help
2y ago
Proper way to access Navigational Properties
C#CC# / help
3y ago