2016-02-27 41 views
0

我充滿了它的用戶 如標記是HR部門和詹姆斯一處也是人力資源部等我應該使用的用戶或用戶的集合在某一類inMVC4

我只是想知道我使用

公共虛擬ICollection用戶{get;組; }

or

public virtual User User {get;組; }

我的部門和倉庫類看起來完全一樣嗎?

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; } 
    } 

可有人還檢查我在User類正確地做了這幾行(你可以參考下面的話)

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 

這是我的實體圖 enter image description here

User類

public class User 
    { 
     public int UserID { get; set; } 
     [StringLength(50, MinimumLength = 1)] 
     public string LastName { get; set; } 
     [StringLength(50, MinimumLength = 1, ErrorMessage = "First name cannot be longer than 50 characters.")] 
     [Column("FirstName")] 
     public string FirstMidName { get; set; } 
     [DataType(DataType.Date)] 
     [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] 
     public DateTime EnrollmentDate { get; set; } 

     public int DepotID { get; set; } 
     public int DepartmentID { get; set; } 
     public int TicketID { get; set; } 


     public string FullName 
     { 
      get { return LastName + ", " + FirstMidName; } 
     } 


     public virtual ICollection<Ticket> Tickets { get; set; }  
     public virtual Administrator Administrator { get; set; } 
     public virtual Department Department { get; set; } 
     public virtual Depot Depot { get; set; } 
    } 
} 
+1

如果'Department'包含多個'User',那麼它的'ICollection Users'(但它不清楚你的'Administrator'表的用途是什麼) –

+0

儘可能快!謝謝 – TykiMikk

回答

1

是的,你應該使用部門因爲它將包含一組用戶。

+0

謝謝你的回答! – TykiMikk

相關問題