I'm pretty new to Entity Framework as a FE Dev doing hobby stuff in my spare time. I'm trying to setup a many to many relationship with the following two classes. I want to have a table with all the users of the application. Each user can have multiple DuBists. In each DuBist there can participate multiple Users but only one User can be the active User. So I try like this (and many other things but that seams most logical to me):
public class DuBist : EntityData
{
public string Title { get; set; }
public virtual User ActiveUser { get; set; }
public int ChangeCount { get; set; }
public virtual ICollection<User> Users { get; set; }
}
public class User : EntityData
{
public string UserId { get; set; }
public string Name { get; set; }
public string ImageRef { get; set; }
[JsonIgnore]
public virtual ICollection<DuBist> DuBists { get; set; }
}
When I add a new DuBist I get this exception:
SqlException: Violation of PRIMARY KEY constraint 'PK_dbo.Users'. Cannot insert duplicate key in object 'dbo.Users'. The duplicate key value is (0).
Mock Data, so one of the users has the id "0".
Looks like I don't know enough to google what is wrong here, any help is appreciated a lot =)