0
votes

i have this two entities setup in this way:

Country -> Id, BrandId ecc. without navigation property Brand -> Id, Description, ecc. with Countries navigation properties

in my webapi i receive a new brand (so without a Id until the save) and i need associate the relative country/countries to this brand. I know that if i have a Brand navigation property i can use it, but i want know if i can do the opposite. I need to find a way to add the BrandId on the Country entity in only 1 save. There is a way in EF to do this without adding the Brand navigation property on Country?

You mean that Brand entity has Countries nav property but Country does not have Brand nav property right ? - dbraillon
yes exactly. I know how to use navigation properties if the Country would have the Brand nav.. but without it there is a possibility to add a new brand associated to a existed country with only one save? - Steph8
Have you tried to retrieve the Country, then add it to the Brand.Countries then add the new Brand to db ? - dbraillon
It will maybe create a duplicate of Country, I'm not sure about this, please let me know, I will update my comment if this happen - dbraillon
if i retrieve the country and add it to brand it throw a new exception because the country already exist (yes try to create a duplicate) - Steph8