Here is what i am trying to do.
1. A company is created which has mulitple Employees.
2. Employees create Events and also that the Employees are assigned to Events i.e.
Employees has many to many relationship with Events. (bridge table)
3. For assigned Event to Employee, it has start date, end date and name of the event.
4. For the assigned Event, now Employee must create Available time for the event. eg. if Event is from 1/1/2021 to 2/1/2020, then Employee should be able to create Available time for him/herself for that time period as he/she is assigned to that event.
How can i create this entity relationship in ENTITY FRAMEWORK, please help.
What I have tried:
1. Created Company class with ID and Navigational Property for Employees (because employees has list of Employees)
public class Company
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int CompanyId { get; set; }
public string Name { get; set; }
public virtual IList<Employee> Employees { get; set; }
}
2. Created Employees class with EmployeeID as PK
public class Employee
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EmployeeId { get; set; }
public string Name { get; set; }
public int CompanyId{ get; set; }
[ForeignKey("CompanyId")]
public Company Company { get; set; }
public virtual IList<EmployeeEvents> EmployeeEvents { get; set; }
}
3. Created Events class with EventID as PK
public class Event
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EventId { get; set; }
public string Name { get; set; }
public DateTime? Start{ get; set; }
public DateTime? End{ get; set; }
public virtual IList<EmployeeEvents> EmployeeEvents { get; set; }
}
4. Created EmployeeEvents bridge class with EmployeeId and EventId as FK
public class EmployeeEvents
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int EmployeeEventId { get; set; }
public int EmployeeId { get; set; }
[ForeignKey("EmployeeId")]
public Employee Employee { get; set; }
public int EventId{ get; set; }
[ForeignKey("EventId")]
public Event Event { get; set; }
}
Please help for the Available time class with appropriate relation and navigation property.