3

Currently I have a table "ComponentAnalysis" and a table "HistoryOfUse" that I am trying to map in Fluent NHibernate.

A component analysis should only have 1 history of use and a history of use should belong to 1 component analysis. This would suggest to me that the tables should be set up for a 1 to 1 mapping. But the designer of the DB didn't set it up that way.

Instead "HistoryOfUse" has a column "ComponentAnalysisID" to specify what component analysis it belongs to. To conform to the database I should have HistoryOfUse References ComponentAnalysis and ComponentAnalysis should HasMany HistoryOfUse.

But if I do this then I need to have a list of type HistoryOfUse which seems fairly annoying. Is there a way to set this up, without changing the database, to allow ComponentAnalysis to have a single HistoryOfUse object even though, according to the DB structure, it should have a list of them?

Justin
  • 2,322
  • 1
  • 16
  • 22

1 Answers1

2

You can use HasOne method to map your classes. Here is the detailed article about this. Your class ComponentAnalysis will "HasOne(x => x.HistoryOfUse)". Column HistoryOfUse.ComponentAnalysisID should be a unique key and a foreign key referenced to the ComponentAnalysis.ID column.

Serhiy
  • 4,357
  • 5
  • 37
  • 53
  • 1
    ... and specify `property-ref`. Similar question: http://stackoverflow.com/questions/244812/nhibernate-one-to-one-mapping-where-second-table-data-can-be-null – Stefan Steinegger Apr 06 '11 at 08:22