如何定义模型所包含的关系,或者只与其中可能涉及的众多模型之一建立关系?例如,我正在开发一个简单的服务台。每个突发事件,问题,变更,发布或服务请求都链接到单个故障单。每个问题也可能与许多事故有关。
public class Incident
{
public virtual Ticket Ticket { get; set; }
public virtual Problem Problem { get; set; }
}
public class Problem
{
public virtual Ticket Ticket { get; set; }
public virtual ICollection<Incident> Incidents { get; set; }
}
public class Change
{
public virtual Ticket Ticket { get; set; }
}
public class Release
{
public virtual Ticket Ticket { get; set; }
}
public class ServiceRequest
{
public virtual Ticket Ticket { get; set; }
}
public class Ticket
{
//I thought about adding virtual properties for each ticket type, but that implies that each ticket can consist of all 5 types at once
}
但是,每张故障单只能与五种故障单类型中的一种相关。也就是说,每个票证都可以与事件,问题,变更等共享主键(如果我可以这样说,那么“选择性”一对一的关系很多)。
如何定义?