我被困在弄清楚这一点。 MVC 5,EntityFramework 我的项目围绕着一项工作。每个Job都有多个ChangeOrders。我安装得很好。工作有一个客户。这也很好。我的问题在于客户员工。 Customer类与CustomerEmployee类具有一对多关系。每个Customer Employee都有一个基本属性和一个Role属性。超级,PM,会计或管理员。那么当我创建一份工作时,我需要选择一个CustomerEmployee Admin / PM等... 这会是什么关系?多对多的关系?在我看来,Job类需要有CustomerEmployeeSuperId,CustomerEmployeePMId,CustomerEmployeeAdminId和CustomerEmployeeAccountantId。
因为现在它只有CustomerEmployeeId
我该怎么做? 当前设置
public class Job
{
//job
public int JobId { get; set; }
public int? JobNumber { get; set; }
public string JobName { get; set; }
public string JobDescription { get; set; }
public int? GeoAreaId { get; set; }
public virtual JobMisc.GeoArea GeoArea { get; set; }
public int? JobClassId { get; set; }
public virtual JobMisc.JobClass JobClass { get; set; }
public int? JobTypeId { get; set; }
public virtual JobMisc.JobType JobType { get; set; }
public Int64? CustomerId { get; set; }
public virtual Customer Customer { get; set; }
public virtual ICollection<ChangeOrder> ChangeOrders { get; set; }
public virtual ICollection<PurchaseOrder> PurchaseOrders { get; set; }
public int? CustomerEmployeeId { get; set; }
public virtual ICollection<CustomerEmployee> CustomerEmployees { get; set; }
}
public class Customer
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)]
public Int64 CustomerId { get; set; }
public string CustomerName { get; set; }
public Int64? CustomerPhoneNumber { get; set; }
public Int64? CustomerFaxNumber { get; set; }
public string CustomerAddress { get; set; }
public string CustomerCity { get; set; }
public string CustomerState { get; set; }
public int? CustomerZipcode { get; set; }
public string CustomerWebsite { get; set; }
public string CustomerOtherShit { get; set; }
public bool? CustomerIsHidden { get; set; }
public virtual ICollection<CustomerEmployee> CustomerEmployees { get; set; }
public List<Job> Jobs { get; set; }
}
public class CustomerEmployee
{
[Key]
public int CustomerEmployeeId { get; set; }
public string CustomerEmployeeFirstName { get; set; }
public string CustomerEmployeeLastName { get; set; }
public string CustomerEmployeeEmail { get; set; }
public Int64? CustomerEmployeePhoneNumber { get; set; }
public Int64? CustomerEmployeeCellNumber { get; set; }
public Int64? CustomerEmployeeFaxNumber { get; set; }
public bool? CustomerEmployeeIsHidden { get; set; }
public string CustomerEmployeeRole { get; set; }
public Int64? CustomerId { get; set; }
public virtual Customer Customer { get; set; }
public int? JobId { get; set; }
public virtual ICollection<Job> Jobs { get; set; }
}
答案 0 :(得分:1)
那么,对于个人工作来说,这将是一对多的关系。对于多个工作,它可能是多对多。
作为管理员的员工是否可能会被作为某些工作的测试人员投入服务?
我建议为JobRoles创建一个子表,一个链接到JobID的表,一个CustomerEmployeeID和一个JobRoleID(假设JobRoles可以灵活处理)。
希望这会有所帮助......