一个或多个实体的验证失败。 UserManager.AddToRole()

时间:2014-02-12 17:29:57

标签: asp.net asp.net-web-api asp.net-mvc-5 asp.net-identity

我正在使用ASP.NET MVC5开发Web Api,并且我已经成功实现了自定义IdentityUser.Like所以

public partial class Authentication : IdentityUser
{
    public Authentication()
    {
        this.LoginSessions = new List<LoginSession>();
    }
    [Required]
    public string PersonId { get; set; }
    public virtual Lecturer Lecturer { get; set; }
    public virtual Student Student { get; set; }
    public virtual ICollection<LoginSession> LoginSessions { get; set; }
}

使用以下地图

public class IdentityUserLoginConfiguration: EntityTypeConfiguration<IdentityUserLogin>
{
    public IdentityUserLoginConfiguration()
    {
        HasKey(t => t.UserId);
    }
}

public class IdentityRoleConfiguration : EntityTypeConfiguration<IdentityRole>
{
    public IdentityRoleConfiguration()
    {
        HasKey(t => t.Id);
    }
}
public class AuthenticationMap : EntityTypeConfiguration<Authentication>
{
    public AuthenticationMap()
    {

        // Primary Key
        this.HasKey(t => t.PersonId);

        // Properties
        this.Property(t => t.PersonId)
            .IsRequired()
            .HasMaxLength(14);

        // Table & Column Mappings
        this.ToTable("Authentication");
        this.Property(t => t.PersonId).HasColumnName("PersonID");

        // Relationships
        this.HasOptional(t => t.Lecturer)
            .WithOptionalPrincipal(t => t.Authentication);
        this.HasOptional(t => t.Student)
            .WithOptionalPrincipal(t => t.Authentication);


    }
}

但现在我的问题是,当我使用

将用户添加到角色时
UserManager.AddToRole()

方法我得到一个DBValidationError 这真让我担心,并希望尽快得到一些帮助

0 个答案:

没有答案