我应该在MVC4中的某个类中使用用户或用户的集合

时间:2016-02-27 04:45:47

标签: c# entity-framework class asp.net-mvc-4

我的部门里面装满了用户 例如,马克在人力资源部,詹姆斯也在人力资源部等。

我只是想知道我使用

public virtual ICollection Users {get;组; }

公共虚拟用户用户{get;组; }

我的部门和仓库类看起来完全一样吗?

X

有人也可以检查我的User类中是否正确地执行了这几行(您可以在下面引用它)

 public class Department
    {
        public int DepartmentID { get; set; }

        [StringLength(50, MinimumLength = 3)]
        public string Name { get; set; }

        [Display(Name = "Administrator")]
        public int UserID { get; set; }

        public virtual ICollection<User> Users { get; set; }
    }

这是我的实体图 enter image description here

用户类

    public virtual ICollection<Ticket> Tickets { get; set; } <-Users can have a collection of tickets because they can open as many tickets as they want.   
    public virtual Administrator Administrator { get; set; } <- Only one user can be one type of admin at a time
    public virtual Department Department { get; set; } <- Only one user can be at one department in at a time
    public virtual Depot Depot { get; set; } <- Only one user can be at one depot a time

1 个答案:

答案 0 :(得分:1)

是的,你应该使用Department,因为它包含一组用户。