gwin003
gwin003

Reputation: 7891

Fluent nHibernate Mapping OneToOne

I have 3 tables:

Table1 - Id, Name
Table2 - Id, Name
Table3 - Id, Table2Id, Address

Table1 and Table2 have the same Id, and table 3 references this Id on Table2. I am trying to map Table1 so it loads the data in Table 3. Here is what I have tried so far, everything is returning null for the Address field:

HasOne(x => x.Address).ForeignKey("Id");
HasOne(x => x.Address).ForeignKey("Table2Id").Cascade.Delete();

Upvotes: 0

Views: 50

Answers (1)

DoctorMick
DoctorMick

Reputation: 6793

HasOne requires all of the tables to have the same primary key which they don't in this case. It looks to me like you need to change the mapping to use References:

References(x => x.Address).KeyColumn("Id");

Upvotes: 2

Related Questions