开发者

Mapping production database

开发者 https://www.devze.com 2023-01-09 21:14 出处:网络
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.

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; }

   开发者_StackOverflow中文版 [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.


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消