测绘生产数据库
我刚刚完成了生产 Oracle 数据库中 100 个表的映射。一路上我注意到很多关系都不是建模的。主要是外键。
我应该修改我的映射以包含适当的关系吗?或者我应该保持映射不变以 100% 反映数据库?
我更倾向于绘制适当的关系,以阐明表格之间的相互关系。这是我的意思的一个例子。
[ActiveRecord("Incident")]
public class Incident : ActiveRecordBase<Incident>
{
[PrimaryKey("IncidentId")]
public int IncidentId { get; set; }
[Property(Column = "CustomerOut")]
public int CustomersOut { get; set; }
[Property(Column = "DistrictNumber")]
public int DistrictNumber { get; set; }
}
[ActiveRecord("District")]
public class District : ActiveRecordBase<District>
{
[PrimaryKey("DistrictNumber")]
public int DistrictNumber { get; set; }
[Property(Column = "DistrictName")]
public string DistrictName { get; set; }
}
正如您所看到的,事件表中的 DistrictNumber 列不是 FK (BelongsTo) 关系,尽管我认为它应该是。
I just completed mapping 100~ tables from our production Oracle database. Along the way I noticed that many relationships were not modelling. Mostly foreign keys.
Should I modify my mappings to include the appropriate relationships? Or should I keep the mapping as is to reflect the database 100%?
I'm more inclined the map the appropriate relationships to clarify how the tables relate to each other. Here is an example of what I mean.
[ActiveRecord("Incident")]
public class Incident : ActiveRecordBase<Incident>
{
[PrimaryKey("IncidentId")]
public int IncidentId { get; set; }
[Property(Column = "CustomerOut")]
public int CustomersOut { get; set; }
[Property(Column = "DistrictNumber")]
public int DistrictNumber { get; set; }
}
[ActiveRecord("District")]
public class District : ActiveRecordBase<District>
{
[PrimaryKey("DistrictNumber")]
public int DistrictNumber { get; set; }
[Property(Column = "DistrictName")]
public string DistrictName { get; set; }
}
As you can see, the DistrictNumber column from the Incident table is not FK (BelongsTo) relationship even though I believe it should be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会包括适当的关系。
这样您就可以从 nhibernate 中充分受益,一个示例是使用 all-delete-orphan 进行映射。 NHibernate 将为您处理所有子记录,否则,您必须自己编写代码来删除子记录。
另外,我想您需要使用延迟加载的关系...再次,我认为您应该正确映射以使您能够完全使用 nhibernate。
I would include de appropriate relationships.
With that you can benefit fully from nhibernate, an example is a mapping with all-delete-orphan. NHibernate will handle all childs for you, without this, you must write at your own the code to delete child records.
Also I guess you need the relationships to use lazy loading... again, I think you should map corectly to enable you to use fully nhibernate.
几天前,我已经回答了您的问题,关于什么是正确的做法:将关系映射为正确的关系。
I already answered to your question here a few days ago about what's the right thing to do: map the relationships as proper relationships.
当然,您应该映射关系,因为它们在数据库中正确存在。使用 ORM(例如 NHibernate),通过完整且正确地映射数据库,您可以获得很多好处!
否则,你会发现自己编写了一堆使用 NHibernate 开箱即用的代码......
Of course you should map the relationships as they properly are in the db. Using an ORM, like NHibernate, you gain a lot by mapping the db fully and properly!
Otherwise, you will find yourself writing a bunch of code, that is out-of-the-box using NHibernate...