I have two objects that I want to associate with a 1: 1 ratio. The user is the main one, and UserActivation is dependent, but I have no idea how this works.
public class User { [Key] public Guid Id { get; set; } public string Name { get; set; } public string Lastname { get; set; } public string Username { get; set; } public virtual UserActivation UserActivation { get; set; } } public class UserActivation { [Key] public Guid Id { get; set; } public Guid UserId { get; set; } public bool Active { get; set; } public virtual User User { get; set; } }
I tried to remove the keyword "virtual", tried to add ForeignKey ("UserId") or ForeignKey ("User"), I even tried to make [Key, ForeignKey ("User") and none of them helped me. I want to make a 1: 1 relationship using only dataannotations. Any help really appreciated. My two classes also have their own PCs.
c # key entity-framework constraints
GrandaS
source share