Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 扩展EF生成的用户类后无法登录_C#_Asp.net Mvc_Asp.net Mvc 4_Entity Framework 5 - Fatal编程技术网

C# 扩展EF生成的用户类后无法登录

C# 扩展EF生成的用户类后无法登录,c#,asp.net-mvc,asp.net-mvc-4,entity-framework-5,C#,Asp.net Mvc,Asp.net Mvc 4,Entity Framework 5,我想寻求一些帮助来了解我的登录页面发生了什么 我有一个名为User.cs的类,它是由EF生成的 public partial class User { public User() { this.PersonnelInfo = new HashSet<PersonnelInfo>(); } public int UserId { get; set; } public str



我想寻求一些帮助来了解我的登录页面发生了什么

我有一个名为User.cs的类,它是由EF生成的

public partial class User
    {
        public User()
        {
            this.PersonnelInfo = new HashSet<PersonnelInfo>();
        }

        public int UserId { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public int RoleId { get; set; }
        public int AccountId { get; set; }


        public virtual ICollection<PersonnelInfo> PersonnelInfo { get; set; }
        public virtual Role Role { get; set; }
        public virtual Account Account { get; set; }
    }
将验证添加到ConfirmPassword属性时出现问题。 我无法登录到我的应用程序。 如果我取消验证,一切都很好

我不想向表中添加另一列,这就是我扩展类用户的原因

希望你能帮助我


谢谢。

如果您能提供更多“我无法登录到我的应用程序”的信息,那会有所帮助,为什么不呢?你有错误吗?但是,如果您不想在数据库中使用ConfirmPassword,则应添加
[NotMapped]
属性。您好@BenRobinson,我尝试登录时没有发生错误。我使用数据库优先的方法。我尝试了这段代码公共部分类用户{[NotMapped][DataType(DataType.Password)][Display(Name=“Confirm Password”)][Compare(“Password”,ErrorMessage=“密码和确认不匹配”)]public string Confirm Password{get;set;}代码,但仍然无法登录。感谢您的回复。是的,但是登录操作的错误消息、异常或结果是什么?您是否在代码中设置了要检查的调试断点?亲爱的@BenRobinson先生,我试图逐个删除验证,似乎
code
Compare(“Password”,ErrorMessage=“密码和确认不匹配”。)]
code
导致了我的问题。@AinneAvila当您说“我无法登录”时,您的意思是“ConfirmPassword属性验证失败”,如果是,验证错误是什么,正在比较的两个属性的值是什么?
[MetadataType(typeof(UserMetadata))]
    public partial class User
    {

    }

    public class UserMetadata
    {
        public int UserId { get; set; }

        [Display(Name = "Username")]
        [Required(ErrorMessage = "Username is required.")]
        public string Username { get; set; }

        [Display(Name = "Password")]
        [Required(ErrorMessage = "Password is required.")]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [Display(Name = "Role")]
        [Required(ErrorMessage = "Role is required.")]
        public int RoleId { get; set; }

        [Display(Name = "Client ID")]
        [Required(ErrorMessage = "Client ID is required.")]
        public int AccountId { get; set; }

        public virtual ICollection<PersonnelInfo> PersonnelInfo { get; set; }
        public virtual Role Role { get; set; }
        public virtual Account Account { get; set; }

    }
public partial class User
    {
        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation do not match.")]
        public string ConfirmPassword { get; set; } 
    }