在实体框架中每个层次结构结构的表中组合两个类
我们正在使用实体框架的每个层次结构继承技术使用表。 我将在此页面上以基本类的方式进行示例类: tabet模型。请不要将班级名称和属性作为集。我不想暴露任何关键的事情。这个问题与结构有关。
public class Contract
{
public int ContractId { get; set; }
public DateTime StartDate { get; set; }
public int Months { get; set;}
public decimal Charge { get; set; }
}
public class MobileContract : Contract
{
public string MobileNumber { get; set; }
}
public class TvContract : Contract
{
public PackageType PackageType { get; set; }
}
public class BroadBandContract : Contract
{
public int DownloadSpeed { get; set; }
}
public enum PackageType
{
S, M, L, XL
}
现在,在我们的情况下,我们的情况是,有一份合同可以是tvontract
和宽带合同
,例如A MultiCntract
。我们不知道该如何处理,因为我们不能从两个类中继承。 如果我们查询dbset< tvontract>
或dbset< broadbandantract>
我们还希望获得Multicnarts
s。
有人知道如何处理这种情况吗?
We're are using the table per hierarchy inheritance technique with Entity Framework.
I'll take the example classes from this page as the basic classes: Table per Hierarchy Inheritance - The Model. Please don't take the class names and properties as set. I didn't want to expose anything critical. This question is just about the structure.
public class Contract
{
public int ContractId { get; set; }
public DateTime StartDate { get; set; }
public int Months { get; set;}
public decimal Charge { get; set; }
}
public class MobileContract : Contract
{
public string MobileNumber { get; set; }
}
public class TvContract : Contract
{
public PackageType PackageType { get; set; }
}
public class BroadBandContract : Contract
{
public int DownloadSpeed { get; set; }
}
public enum PackageType
{
S, M, L, XL
}
Now, in our case we have the situation that there is a contract that can be both, a TvContract
and a BroadBandContract
, e.g. a MultiContract
. We don't know how to deal with this since we cannot inherit from two classes.
If we query the DbSet<TvContract>
or DbSet<BroadBandContract>
from the we also want to get the MultiContract
s.
Does someone have an idea how to deal with this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到我们当前的阶级结构是继承的。在我看来,它看起来像是构图。合同可能包含不同的分包合同,一旦合同到期,分包也会过期。但是,分包合同具有不同的类型,这就是您可以使用的优势。您可能还会看到某人添加或删除其合同类型的软件包并不是真正静态的要求。我会设计来处理这一点。我还希望通过
分包合同
单独使用月份
允许使用分包合同
obejcts的可变启动日期和结束日期。我将重新设计这样的类,然后仅与分包合同过滤器查询合同。
I see our current class structure is of inheritance. While to me it looks like composition. A contract may contain different subcontracts and once the contract expires, subcontracts too expire. However, subcontracts are of different types and that is what you could use for your advantage. You may also see a requirement where someone would add or remove the packages they have thus contract type is not really static. I would design to handle that. I would have also preferred an end date or
Months
individually onSubContract
allowing for variable start and end dates forSubContract
obejcts.I would redesign the classes like this and then only query Contract potentially with SubContract based filters.