I have those two entities:
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string IdsrvUniqueId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string About { get; set; }
public GenderEnum Gender { get; set; }
public DateTime BirthDate { get; set; }
public string PhoneNumber { get; set; }
}
public class NotificationSetting
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public bool AutomaticallySubscribeToAllGroups { get; set; }
public bool AutomaticallySubscribeToAllGroupsWithTag { get; set; }
}
what I want to do is implemente 1:1 relationship between them but currently with no success. I tried to use data notations and decorate them to look like this:
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
..........
// Navigation properties
public virtual NotificationSetting NotificationSettings { get; set; }
}
public class NotificationSetting
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[ForeignKey("User")]
public Guid Id { get; set; }
....
// Navigation properties
public virtual User User { get; set; }
}
It compiles, generates migration file but when I try to add new user I get an error. Can you please tell me what is wrong here and How can I achieve my goal.