Free Nhibernate, how to handle it, there are many that really only have one?

I currently have a “ComponentAnalysis” table and a “HistoryOfUse” table that I am trying to display in Fluent NHibernate.

Component analysis should have only 1 usage history, and usage history should belong to 1-component analysis. This tells me that the tables should be configured to display from 1 to 1. But the database designer did not configure it that way.

Instead, HistoryOfUse has a column called ComponentAnalysisID to indicate which component analysis it belongs to. To match the database, I had to have links to HistoryOfUse. ComponentAnalysis and ComponentAnalysis must have HasMany HistoryOfUse.

But if I do, I need a list of type HistoryOfUse, which seems pretty annoying. Is there a way to set this without modifying the database to allow ComponentAnalysis to have one HistoryOfUse object, although, according to the database structure, it should have a list of them?

+3
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1765200/


All Articles