Elegant way to model multiple reviewers for a form in MVC with Entity First

How would you model the data on the form where there are multiple reviewers. Do you create multiple collections or use an array and adding a type field? or something else? When I used multiple instances as commented out, it created multiple MainForm_id in the employee table.

//main form

public class MainForm { public int Id { get; set; } public virtual ICollection<Employee[]> EmployeeArray { get; set; } //public virtual ICollection<Employee> EmployeeReviewing { get; set; } //public virtual ICollection<Employee> EmployeeSupervisor { get; set; } //public virtual ICollection<Employee> EmployeeManager { get; set; } //public virtual ICollection<Employee> EmployeeBigBoss { get; set; } }

//employee

public class Employee { public int Id { get; set; } public int ProgramEntryId { get; set; } public int ReviewerTypeId { get; set; } public virtual MainForm MainForm { get; set; } public virtual ReviewerType ReviewerType { get; set; } }

--------------Solutions-------------

I would not store the collections directly on the MainForm class. Instead I would have a new class that houses both an employeeId and a formId.

///Form

public class MainForm
{
[Key]
public int Id { get; set; }
}

///Employee

public class Employee
{
[Key]
public int Id { get; set; }
[ForeignKey("EmployeeType")]
public int EmployeeTypeId {get;set;}

}

///EmployeeType

public class Employee
{
[Key]
public int Id { get; set; }
}

///EmployeeReview

public class EmployeeReview
{
[Key]
public int Id { get; set; }
[ForeignKey("Employee")]
public int EmployeeId { get; set; }
[ForeignKey("MainForm ")]
public int MainFormId{ get; set; }

public virtual Employee Employee { get; set; }
public virtual MainForm MainForm { get; set; }
}

Then you would simply query your form such that:

var reviews = EmployeeReview.Where(x => x.Employee.EmployeeTypeId ==
(int)Enum.Employee.EmployeeSupervisor)

reviews at this point would grant you access to the required form and employees of said type who reviewed the form.

Category:asp.net mvc Time:2018-11-09 Views:1

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.519 (s). 13 q(s)