views:

52

answers:

3

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.

+1  A: 

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.

Rafael Mueller
+1  A: 

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.

Mauricio Scheffer
+1  A: 

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

gillyb