简体   繁体   中英

Entity Framework Model using Remote

I have been learning asp.net mvc for a while now and I am coming to grips with using the entity framework,

I have the following Model

[Table("User")]
public partial class User
{
    //  [ConcurrencyCheck]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]

    [Key]
    public int Id { get; set; }

    [Required]
    [Display(Name = "User Name")]
    [Remote("IsUserNameAvailable", "User", ErrorMessage = "User name already Exists.")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [StringLength(150, MinimumLength = 6)]
    [Display(Name = "Password")]
    public string Password { get; set; }
    [Required]
    public string FirstName { get; set; }

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

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email")]
    [Remote("IsEmailAvailable", "User", ErrorMessage = "Email Address Already Exists.")]
    public string Email { get; set; }

}

This all works fine when I register a user. But my problem is that I tried Doing something like this for login

[Table("User")]
public partial class Login
{
    //  [ConcurrencyCheck]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]

    [Key]
    public int Id { get; set; }

    [Required]
    [Display(Name = "User Name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [StringLength(150, MinimumLength = 6)]
    [Display(Name = "Password")]
    public string Password { get; set; }


}

The reason I wanted this was so that I can use a model that would not have to use the remote Attribute as I wouldn't be checking if the username exists

The error I get when I do this says that I cannot use separate entities for the same table. I am trying to get around not triggering the remote attribute for the login part.

Has anyone come across this?

Thanks,

删除部分的访问修饰符和[Table(“ User”)],[Key]属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM