1

我有一个带字段的部门表

public class Department
{

    [ScaffoldColumn(false)]
    public int DepartmentId { get; set; }
    [Required(ErrorMessage = "*")]        
    [StringLength(100)]

    public string DepartmentName { get; set; }
    public bool Active { get; set; }

    public int LocationID { get; set; }
    public virtual Location UsersCompanyLocation { get; set; }
}

和一个员工表

public class Employee
{
    [ScaffoldColumn(false)]
    [Key]
    public int UserId { get; set; }

    [Required(ErrorMessage = "*")]
    [StringLength(50)]
    public string FirstName { get; set; }

    [StringLength(50)]        
    public string LastName { get; set; }


    public string UserName { get; set; }
    [DataType(DataType.Password)]
    public string Password { get; set; }

    [Required(ErrorMessage = "*")]
    [StringLength(50)]
    public string IDCardNo { get; set; }

    [StringLength(50)]
    public string Address { get; set; }

    [StringLength(50)]
    public string City { get; set; }

    [StringLength(50)]
    public string Zip { get; set; }

    [StringLength(50)]
    public string Mobile { get; set; }

    [StringLength(50)]        
    public string HomePhone { get; set; }


    public int? DesignationId { get; set; }
    public Designations EmployeeDesignation { get; set; }


    public int? DepartmentID { get; set; }
    public virtual Department UserDepartment { get; set; }

    [Display(Name = "Company", ResourceType = typeof(Translations.Translation))]
    public int CompanyID { get; set; }
    public virtual Company UserCompany { get; set; }


    public int? LocationID { get; set; }
    public virtual Location UsersCompanyLocation { get; set; }

    [StringLength(500)]
    [Display(Name = "Pic", ResourceType = typeof(Translations.Translation))]
    public string Pic { get; set; }

    [Required(ErrorMessage = "*")]
    [DataType(DataType.Date)]
    [Display(Name = "HireDate", ResourceType = typeof(Translations.Translation))]
    public DateTime HireDate { get; set; }

    [Required(ErrorMessage = "*")]
    [DataType(DataType.Date)]
    [Display(Name = "DateofBirth", ResourceType = typeof(Translations.Translation))]
    public DateTime DOB { get; set; }

    [Required(ErrorMessage = "*")]
    [StringLength(50)]
    [Display(Name = "MaritalStatus", ResourceType = typeof(Translations.Translation))]
    public string MaritialStatus { get; set; }

    [StringLength(50)]        
    public string AccountNumber { get; set; }

    [Required(ErrorMessage = "*")]
    [StringLength(256)]        
    [DataType(DataType.EmailAddress, ErrorMessage = "*")]
    public string PersonalEmail { get; set; }

    [Required(ErrorMessage = "*")]
    [StringLength(256)]        
    [DataType(DataType.EmailAddress, ErrorMessage = "*")]
    public string OfficialEmail { get; set; }


    public int? RoleId { get; set; }
    public virtual Roles UserRole { get; set; }

    public int? EmploymentStatusID { get; set; }
    public virtual Employment EmploymentStatus { get; set; }
}

现在我的场景是我想将一名员工作为经理分配给一个部门,并且从剩余的员工池中,我可以将员工分配给那个部门。我正在使用代码优先 EF 技术,我无法创建一个适当的类来处理这个场景。其次,我想使用两次列表框,第一次我们可以从中选择一名员工作为经理,第二次我想从剩余的员工池中选择多名员工。任何人都可以在这个场景中帮助我吗

用完一整天后,我已经完成了数据库部分

我必须制作另一个表(在 EF CodeFirst 中关闭一个类)“DepartmentManager”

public class DepartmentManager
{
    [ScaffoldColumn(false)]

    public int ID { get; set; }

    public int DepartmentId { get; set; }
    public virtual Department AssignedDepartment { get; set; }

    public int UserID { get; set; }
    public virtual Employee ManagerialEmployee { get; set; }

    public virtual List<DepartmentEmployees> DepartmentEmployees { get; set; }

该表有一个 UserID 外键,现在为了将员工分配给部门,我将使用复合键创建另一个表“DepartmentEmployees”

public class DepartmentEmployees
{
    [ScaffoldColumn(false)]
    [Key, Column(Order = 0)]
    public int ID { get; set; }
    [ScaffoldColumn(false)]
    [Key, Column(Order = 1)]
    public int EmployeeId { get; set; }        
}

现在要问两件事,如何使外键UserID 唯一以使其不会重复,第二如何使用List Box使得在一个中List Box只选择一个员工,在第二个中,我们可以选择剩余的员工,以及如何填写2ndList Box这样被选为经理的员工不会出现在 2nd List Box??????????????

4

0 回答 0