I have a Department filled with Users in it eg Mark is in HR Department and James is also in HR Department etc
I'm just wondering do I use
public virtual ICollection Users { get; set; }
or
public virtual User User { get; set; }
for my department and depot classes which look exactly the same?
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; }
}
Can someone also check if I did these few lines correctly in my User class(You can reference it below)
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
User class
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; }
}
}
Department
contains multipleUser
, then itsICollection<User> Users
(but its not clear what the purpose of yourAdministrator
table is) – user3559349