代码首先使用不同的实体

时间:2013-05-19 13:22:13

标签: asp.net-mvc-4 ef-code-first

我有三个模型类和三个视图。模型如下:

 public class BASLPApplicationFormModel
        {
            [Key]
            [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
            public int BASLPApplicationID { get; set; }


            public string BASLPApplicationNo { get; set; } 

            public string ApplicantName { get; set; }

            [DataType(DataType.Date)]
            [Display(Name = "Date of Birth", Prompt = "DD/MM/YYYY")]
            public DateTime DateOfBirth { get; set; }        


            [Required]
            [Display(Name = "Email-ID")]        
            public string EmailID { get; set; }

}

和第二

  public class DPPHIApplicationFormModel
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int DPPHIApplicationID { get; set; }


        public string DPPHIapplicationNo { get; set; }

        [Required]
        [Display(Name = "Name of Applicant")]
        [DataType(DataType.Text)]
        public string Name { get; set; }

        [Required]
        [Display(Name = "Expansion of Initial")]
        [DataType(DataType.Text)]
        public string InitialExpansion { get; set; }


        [DataType(DataType.Date)]
        [Display(Name = "Date of Birth", Prompt = "MM/DD/YYYY")]
        public DateTime DateOfBirth { get; set; }



        [Required]
        [Display(Name = "Email-ID")]
        [DataType(DataType.EmailAddress)]
        public string EmailID { get; set; }
}

和第三

    public class DTYDHHApplicationFormModel
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int DTYDHHApplicationID { get; set; }    


        public string DTYDHHAapplicationNo { get; set; }

        [Required]
        [Display(Name = "Name of Applicant")]
        [DataType(DataType.Text)]
        public string name { get; set; } 



        [RegularExpression("^([0-9]+)$", ErrorMessage = "Invalid Phone Number")]
        [DataType(DataType.PhoneNumber)]
        [Display(Name = "Land Line Number")]
        public string Phone { get; set; }    

        [Required]
        [Display(Name = "Email-ID")]
        [DataType(DataType.EmailAddress)]
        public string EmailID { get; set; }
}

电子邮件模型,

[Table("Emails")]
    public class UserEmails
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        public string UserEmailID { get; set; }
    }

此处,用户可以与任何表单进行互动并相应地提交表单。

我想使用代码优先方法将所有电子邮件条目收到我的电子邮件表,请告诉我如何实现。