Authentication Can';t清除用户配置文件<-&燃气轮机;角色关系(使用实体框架5和MVC4)

Authentication Can';t清除用户配置文件<-&燃气轮机;角色关系(使用实体框架5和MVC4),authentication,asp.net-mvc-4,entity-framework-5,Authentication,Asp.net Mvc 4,Entity Framework 5,使用EntityFramework5、MVC4和CodeProject中的CheckBoxList 1.4.4.3-beta2,我只是试图清除多对多关系中的UserProfile对象角色关系 UserProfileController(精简-不保存标量属性和选定角色): UserProfileRepository(和RoleRepository)是标准的脚手架存储库: public void InsertOrUpdate(UserProfile userprofile) {

使用EntityFramework5、MVC4和CodeProject中的CheckBoxList 1.4.4.3-beta2,我只是试图清除多对多关系中的UserProfile对象角色关系

UserProfileController(精简-不保存标量属性和选定角色):

UserProfileRepository(和RoleRepository)是标准的脚手架存储库:

    public void InsertOrUpdate(UserProfile userprofile)
    {
        if (userprofile.UserId == default(int)) {
            // New entity
            context.UserProfiles.Add(userprofile);
        } else {
            //// Existing entity
            context.Entry(userprofile).State = EntityState.Modified;
        }
    }
用户配置文件:

public ICollection<Role> Roles { get; set; }
公共ICollection角色{get;set;}
角色:

public ICollection用户配置文件{get;set;}

我没有得到任何异常,但也没有对数据库执行任何更新。这可能是由使用相同db表的身份验证提供程序(SimpleMembershipProvider)引起的吗?我应该实现自定义成员资格提供程序吗?在我的应用程序中,我还有其他几个多对多关系,它们都是以与此相同的方式组成的,它们都像一个符咒一样工作。

这是我在重写UserProfile上的Equals方法时犯的一个错误,使所有比较返回false

public ICollection<Role> Roles { get; set; }
public ICollection<UserProfile> UserProfiles { get; set; }