C#C
C#3y ago
Lounder

✅ EF Core navigational properties

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

class Address
- ...

This causes an error:
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

Initialization code:
            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
Was this page helpful?