如何在同一模型中添加重复的外键

时间:2016-07-19 04:20:30

标签: asp.net-mvc entity-framework model asp.net-mvc-scaffolding

我在ASP MVC项目中工作,它使用MvcScaffolding很多,我有一个项目和一个客户端模型,事情是项目必须以两种方式与客户端模型相关联(Billing客户端和Service Client,并且这两个数据来自同一客户端模型)

我不知道怎么做,这是我的模特

客户端模型

    public class ClientsX 
    {
        [Key]
        public int idcliente { get; set; }

        [Required(ErrorMessage = "A Legal ID is required")]
        [StringLength(150)]
        [Display(Name = "Company Name: ")]
        public string CompanyName { get; set; }

        [StringLength(150)]
        [Display(Name = "Legal ID: ")]
        public string LegalID { get; set; }

        [Required(ErrorMessage = "A Contact First Name is required")]
        [StringLength(150)]
        [Display(Name = "First Name: ")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "A Contact Last Name is required")]
        [StringLength(150)]
        [Display(Name = "Last Name: ")]
        public string LastName { get; set; }

        [Required(ErrorMessage = "A Contact Email Address is required")]
        [DataType(DataType.EmailAddress, ErrorMessage = "Please enter a valid email address")]
        [EmailAddress(ErrorMessage = "Please enter a valid email address")]
        [StringLength(150)]
        [Display(Name = "Email Address: ")]
        public string email { get; set; }

        [Required(ErrorMessage = "A Phone Number is required")]
        [StringLength(15)]
        [Display(Name = "Phone: ")]
        public string phone { get; set; }

        [Required(ErrorMessage = "An Username is required")]
        [MaxLength(50, ErrorMessage = "Your Username cannot exceed 50 characters")]
        [RegularExpression(@"^[\S]*$", ErrorMessage = "No White spaces are Accepted")]
        [Display(Name = "Username: ")]
        public string username { get; set; }

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

    }

项目模型

    public class Project
    {
        [Key]
        public int idProject { get; set; }

        [Display(Name = "Billing Client")]
        [Required(ErrorMessage = "This Field is required")]
        public int ClientsXId { get; set; }

        [Display(Name = "Client")]
        [Required(ErrorMessage = "This Field is required")]
        public int ClientsXId { get; set; }

        [Display(Name = "Status")]
        [Required(ErrorMessage = "This Field is required")]
        public int estatusId { get; set; }
   }

是的,我知道ClientsXId是重复的,但是是故意的,因为我需要在项目模型中拥有相同的数据,但它给了我这个错误:

错误5类型' SSMS_2._0._1.Models.Project'已经包含了< CientsXId'的定义D:\ PC \ Visual Studio 2013 \ Projects \ SSMS-2.0.1 \ SSMS-2.0.1 \ Models \ ProjectModel.cs 99 20 SSMS_2._0._1

我该如何做到这一点?

0 个答案:

没有答案