0
지정 클래스속성 'DepartmentID은'탐색 속성으로
public class Designation
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[ForeignKey("DepartmentID")]
public int DepartmentID { get; set; }
public bool IsActive { get; set; }
public string AddedBy { get; set; }
public DateTime AddedDate { get; set; }
public string UpdateBy { get; set; }
public DateTime UpdateDate { get; set; }
public virtual Department Department { get; set; }
}
부서 클래스
public class Department
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int DepartmentID { get; set; }
public string DepartmentName { get; set; }
public bool IsActive { get; set; }
public string AddedBy { get; set; }
public DateTime AddedDate { get; set; }
public string UpdateBy { get; set; }
public DateTime UpdateDate { get; set; }
public virtual ICollection<Designation> Designations { get; set; }
}
EmployeeInfo 클래스
public class EmployeeInfo
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public int EmployeeID { get; set; }
public int DepartmentID { get; set; }
[ForeignKey("DepartmentID")]
public virtual Department Department { get; set; }
[Required(ErrorMessage = "Employee Name is Required"), Display(Name = "Name")]
public string EmployeeName { get; set; }
[Required(ErrorMessage = "Employee Bangla Name is Required"), Display(Name = "Bangla Name")]
public string EmployeeBanglaName { get; set; }
[Required(ErrorMessage = "Department Name is Required")]
public string Department { get; set; }
[Required(ErrorMessage = "Designation is Required")]
public string Designation { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime JoiningDate{ get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime DateOfBirth { get; set; }
[Required(ErrorMessage = "BloodGroup is Required"), Display(Name = "Blood Group")]
public string BloodGroup { get; set; }
[Required(ErrorMessage = "Gender is Required")]
public gender Gender { get; set; }
[Required(ErrorMessage = "Father Name is Required"), Display(Name = "Father Name")]
public string FatherName { get; set; }
[Required(ErrorMessage = "Mother Name is Required"), Display(Name = "Mother Name")]
public string MotherName { get; set; }
[Required(ErrorMessage = "Husband/Wife Name is Required"), Display(Name = "Spouse Name")]
public string SpouseName { get; set; }
public string ChildrenNumber { get; set; }
public string CardNumber { get; set; }
[Required(ErrorMessage = "Contact No is Required"), DataType(DataType.PhoneNumber)]
public string ContactNo { get; set; }
[Required(ErrorMessage = "Email is Required"), DataType(DataType.EmailAddress), StringLength(200)]
public string Email { get; set; }
[Required(ErrorMessage = "HomeContactNo is Required"),DataType(DataType.PhoneNumber)]
public string HomeContactNo { get; set; }
[Required(ErrorMessage = "District Name is Required")]
public string District { get; set; }
[Required(ErrorMessage = "Thana is Required")]
public string Thana { get; set; }
[Required(ErrorMessage = "Village Name is Required")]
public string Vill { get; set; }
[Required(ErrorMessage = "Post Code is Required")]
public string PostCode { get; set; }
public string Image { get; set; }
public byte[] picture { get; set; }
public bool IsActive { get; set; }
public string AddedBy { get; set; }
public DateTime AddedDate { get; set; }
public string UpdateBy { get; set; }
public DateTime UpdateDate { get; set; }
}
를 구성 할 수 없습니다
성 열거
public enum gender
{
Male,
Female,enter code here
Other
}
세 가지 모델/테이블과 departmentID로 외래 키 관계를 만들고 싶지만 오류는 다음과 같이 표시됩니다.> 'DepartmentID'속성을 탐색 속성으로 구성 할 수 없습니다. 이 속성은 유효한 엔터티 형식이어야하며 속성은 추상화되지 않은 getter 및 setter를 가져야합니다. 컬렉션 속성의 경우 유형이 ICollection을 구현해야합니다. 여기서 T는 유효한 엔터티 유형입니다. 내 모델은 –
입니다. 댓글에 질문을 쓰면 안됩니다. 귀하의 질문을 편집하고 거기서 귀하의 세부 사항을 적어보십시오. –
'[ForeignKey ("DepartmentID")]''public int DepartmentID {get; 세트; }} (필요한 경우,'public virtual Department Department {get; set;} '속성에 적용해야 할 필요가있다. (당신이 아닌 경우)'[DatabaseGenerated (DatabaseGeneratedOption.Identity) ]'그것에서 또한. –