日期:2014-05-17  浏览次数:20611 次

EF中,关于外键引发循环报错的疑惑
C# code
public class User
    {
        [Key]
        [Display(Name = "工号")]
        [Required(ErrorMessage = "*")]
        [StringLength(15, ErrorMessage = "不能超过15个字符")]
        public string UserNo { get; set; }

        [Display(Name = "密码")]
        [Required(ErrorMessage = "*")]
        [StringLength(20, ErrorMessage = "不能超过20个字符")]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [Display(Name = "姓名")]
        [Required(ErrorMessage = "*")]
        [StringLength(10, ErrorMessage = "不能超过10个字符")]
        public string RealName { get; set; }

        [Display(Name = "性别")]
        [Required(ErrorMessage = "*")]
        public string Sex { get; set; }

        [Display(Name = "出生年月")]
        [Required(ErrorMessage = "*")]
        public DateTime? Birthday { get; set; }

        [Display(Name = "身份证号码")]
        public string IDCardNumber { get; set; }

        [Display(Name = "身高")]
        public int? Height { get; set; }

        [Display(Name = "照片")]
        public string PhotoUrl { get; set; }

        /// <summary>
        /// 是否残疾 
        /// </summary>
        [Display(Name = "残疾人")]
        public bool IsDisabled { get; set; }

        [Display(Name = "国家")]
        [Required(ErrorMessage = "*")]
        public int Country { get; set; }

        [Display(Name = "户口所在地")]
        public string DomicilePlace { get; set; }

        /// <summary>
        /// 婚姻状态 
        /// Y已婚
        /// N未婚
        /// </summary>
        [Display(Name = "婚姻状态")]
        public string IsMarried { get; set; }

        [Display(Name = "政治面貌")]
        [Required(ErrorMessage = "*")]
        public int PoliticsStatus { get; set; }

        
        [Display(Name = "学历")]
        public int? Education { get; set; }

        [Display(Name = "毕业学校")]
        public string GraduateSchool { get; set; }

        [Display(Name = "最高学位")]
        public string Degree { get; set; }

        [Display(Name = "获得学校")]
        public string DegreeBySchool { get; set; }


        [Display(Name = "居住地址")]
        public string ResidentialAddress { get; set; }

        [Display(Name = "邮编")]
        public string Post { get; set; }

        [Display(Name = "手机号码")]
        public string TelPhoneNumber { get; set; }

        [Display(Name = "电子邮箱")]
        public string Email { get; set; }

        [Display(Name = "QQ号码")]
        public string QQ { get; set; }

        [Display(Name = "MSN")]
        public string MSN { get; set; }


        [Display(Name = "入职日期")]
        [Required(ErrorMessage = "*")]
        public DateTime? JoinDate { get; set; }

        [Display(Name = "职位")]
        [Required(ErrorMessage = "*")]
        public int PositionID { get; set; }

        [ForeignKey("PositionID")]
        public virtual Position Position { get; set; }

        /// <summary>
        /// 在职/兼职/离退/实习
        /// </summary>
        [Display(Name = "员工状态")]
        public string State { get; set; }

        [Display(Name = "工资类型")]
        [Required(ErrorMessage = "*")]
        public int PayType { get; set; }

        [Display(Name = "考核类型")]
        [Required(ErrorMessage = "*")]
        public int CheckType { get; set; }

        /// <summary>
        /// 是否 超级用户 
        /// 1是
        /// 0否
        /// </summary>
        [Display(Name = "用户类型")]
        public string IsSuper {