0

I would like to create collection of Users in User class, but EF returns fail "Multiplicity constraint violated."

[Table("Users")]
public class UsersDbSet
{
    public UsersDbSet()
    {
        Friends = new List<UsersDbSet>();
    }

    [Key, Required, DatabaseGenerated(DatabaseGeneratedOption.Identity), Index(IsUnique = true)]
    public int UserID { get; set; }

    [Required, Index(IsUnique = true), MaxLength(MaxLoginLength)]
    public string Login { get; set; }

    [Required]
    public string Password { get; set; }

    public virtual ICollection<UsersDbSet> Friends { get; set; }
}

I don't understund where is the problem...

lbarczynski
  • 170
  • 11
  • possible duplicate of [Self-referencing many-to-many recursive relationship code first Entity Framework](http://stackoverflow.com/questions/5125052/self-referencing-many-to-many-recursive-relationship-code-first-entity-framework) – Daniel Auger Dec 28 '14 at 19:34
  • *When* do you get this error? – Gert Arnold Dec 28 '14 at 22:05
  • I have 3 users: User1, User2 and User3. When i adding User2 and User3 to User1.Friends collection everything is ok, but when I try to add for example User2 to User3.Friends I get this error. Problem is not actual couse i've change my mind, i'd create FriendsDbSet couse I need information about confirmation friends invite and date of friend adding, but You can write solution for antoher user and for me, becouse I still don't understund what is reason of this problem :) – lbarczynski Dec 29 '14 at 18:33

0 Answers0