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# 远程实体框架模型_C#_Asp.net Mvc_Database_Entity Framework - Fatal编程技术网

C# 远程实体框架模型

C# 远程实体框架模型,c#,asp.net-mvc,database,entity-framework,C#,Asp.net Mvc,Database,Entity Framework,我学习asp.net mvc已经有一段时间了,现在我开始学习使用实体框架 我有下面的型号 [Table("User")] public partial class User { // [ConcurrencyCheck] [DatabaseGenerated(DatabaseGeneratedOption.None)] [Key] public int Id { get; set; } [Required] [Display(Name = "

我学习asp.net mvc已经有一段时间了,现在我开始学习使用实体框架

我有下面的型号

[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; }

}
当我注册一个用户时,这一切都很好。但我的问题是,我尝试过这样做登录

[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; }


}
我希望这样做的原因是,我可以使用一个不必使用remote属性的模型,因为我不会检查用户名是否存在

执行此操作时出现的错误是,我不能对同一个表使用单独的实体。我试图避免触发登录部分的远程属性

有人见过这个吗


谢谢,

删除访问修饰符部分 及 [表(“用户”)],[键]
属性

非常感谢您的回答,但是如果我删除表,我的模型如何知道我的表是如何映射的?我有一个Id作为主键,这是什么原因造成的?实际上,当有人提交数据时,这将是一个模型类,用于在视图上显示数据。您将把数据从模型类转换为实体类,因此在模型类上,您不必提及您的关键字段是什么,等等,您需要一个数据模型(不应包括视图特定属性,如
[Remote]
),然后使用视图模型-请参阅