需要有关使用 Entity Framework 4.1 Code First 和基本类型进行模型设计的建议
我需要一些关于我正在设计的模型的部分建议。正如您在我的 Rfi 实体中看到的,我有一个 BaseImpact 类型的集合。可以将多种类型的影响添加到该集合中。每种影响类型都有其自己的属性。作为示例,我创建了成本影响和进度影响。现在,这些并没有太大的不同,但你明白了。我试图弄清楚如何使用相同类型的模型,然后将映射/关系添加到数据库中。我真的希望 BaseImpact 是抽象的,但我可能需要它位于数据库中,但我不是用户。
public class Rfi
{
public ICollection<BaseImpact> Impacts { get; set; }
}
public class BaseImpact : BaseEntity
{
#region Navigation
public virtual ICollection<Comment> Comments { get; set; }
#endregion
}
public class CostImapct: BaseImpact
{
public decimal Cost { get; set; }
}
public class ScheduleImpact: BaseImpact
{
public int days { get; set; }
}
I need some advice on part of my model I am designing. As you can see in my Rfi entity, I have a collection of BaseImpact types. There will be several types of impacts that can be added to that collection. Each impact type has its own properties. As an example I created a Cost Impact and a Schedule Impact. Now, these are not very different, but you get the idea. I am trying to figure out how I can use this same type of model and then add the mappings / relationships to the database. I'd really like the BaseImpact to be abstract, but I may need it to be in the DB, but I am not usre.
public class Rfi
{
public ICollection<BaseImpact> Impacts { get; set; }
}
public class BaseImpact : BaseEntity
{
#region Navigation
public virtual ICollection<Comment> Comments { get; set; }
#endregion
}
public class CostImapct: BaseImpact
{
public decimal Cost { get; set; }
}
public class ScheduleImpact: BaseImpact
{
public int days { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参见这个 系列 帖子介绍了在 EF Code First 中对继承层次结构进行建模的不同选项。
See this series of posts on different options for modeling inheritance hierarchies in EF Code First.