Lets say I have an object Account, with a BillToAddress, here is the hierarchy of the object.
Account > BillToAddress > City > State > Country
The repository includes the full BillToAdress when reading like so:
public static Account GetByAccountNumber(
this IRepository<Account> repository,
.Include(e => e.BillToAddress.City.State.Country)
.FirstOrDefault(e => e.AccountNumber == accountNumber);
This works well, but what is the preferred way of setting a new Country on the object? I tried just setting the Account.BillToAddress.City.State.Country = null, then Account.BillToAddress.City.State.Country.CountryId = myNewCountryId then
Account.ObjectState = ObjectState.Modified
...but I get a DbUpdateException due to relation.
Do I have to read the Country by Id from the repository, then set like so?
Account.BillToAddress.City.State.Country = newCountryReadFromDB
Account.BillToAddress.City.State.Country.ObjectState = ObjectState.Modified?
I wanted to avoid the read if I already know the CountryId.
Thanks for the awesome framework!!! Great job!