I have a class that I first inserting the Seed () method to register the users already have a combo box filled with the necessary and unique Caunties, then their name is the Id itself.
The duplicate key problem happens when I enter a user which in turn has an address, which has the city, the city has relationship with County, to insert (UserManager.CreateAsync () standard Asp.Net MVC design method with implementation of IdentityUser and etc.) I get an error, because instead of taking a AddOrUpdate () it tries to insert a new one with this key.
How do I solve the problem? I need to set for this model always be AddOrUpdate ().
public class ApplicationUser : IdentityUser
{
[Required]
public virtual Address Address { get; set; }
}
public class Address
{
[Required]
public virtual City City { get; set;}
}
public class City
{
[Required]
public virtual County County { get; set;}
}
public class County
{
[Key]
public string NameId { get; set;}
}