I have an ASP.NET identity user class that I wish to extend with a many-to-many relationship:
public class MyUser : IdentityUser
{
public virtual ICollection<Group> Groups { get; set; }
public MyUser()
{
Groups = new List<Group>();
}
}
Group is defined thus:
public class Group
{
public string Name { get; set; }
//public ICollection<MyUser> MyUsers { get; set; }
}
When I add a migration for these objects, I get a MyUser_Id field on my Groups table, which gets overwritten whenever any user adds a group to their collection.
If I uncomment the other end of the relationship in the Group class, I do get a GroupMyUsers join table, which I can seed using Group. However, when I attempt to access the MyUser.Groups property an EntityCommandExecutionException
is thrown, stating that 'MyUserGroups' is not a valid object.