Seamless NHibernate match?

I have a one-to-one relationship problem in free nHibernate.

I have the following relational table from AdventureWorks2008 database.

BusinessEntity (Table)
    BusinessEntityId Int (PK, Identity)

Person (Table)
   BusinessEntityId int (PK, Reference with BusinessEntity table)
   FullName varchar(255)

      

The relationship between the BusinessEntity table and the Person table is one-to-one.

How can I transfer freely without any extra field like "Id" in Person table?

There should be 2 classes for Person and one for BusinessEntity or a suitable model to best describe the above relationship.

Thank you Ashraf.

+2


source to share


1 answer


Assuming your Person mapping is pretty standard, how do you do it by saying:

Id(x => x.BusinessEntityId)
     .GeneratedBy.Foreign("BusinessEntity");

      

in the Person class.



This assumes that your Person class has a BusinessEntity property that is of type BusinessEntity.

You also need to map the BusinessEntity to Person with a bounded true value (to say that Person's primary key is a foreign key reference for the BusinessEntity).

The key point is GeneratedBy.Foreign () to say that your identity is generated by a reference to another class.

+4


source







All Articles