测绘生产数据库

发布于 2024-09-12 14:06:09 字数 839 浏览 6 评论 0原文

我刚刚完成了生产 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落日海湾 2024-09-19 14:06:09

我会包括适当的关系。

这样您就可以从 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.

夜声 2024-09-19 14:06:09

几天前,我已经回答了您的问题,关于什么是正确的做法:将关系映射为正确的关系

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.

亚希 2024-09-19 14:06:09

当然,您应该映射关系,因为它们在数据库中正确存在。使用 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文