views:

21

answers:

1

I have a class whose primary key is a single column, which is a reference to another object's single column primary key. The only way I can see to map this in NHibernate is to pretend it's a composite key (even though it's a single column key) and use the key-reference mapping. Is there a more appropriate way?

Snippet below:

class CompanyExportCriteria
  public Company Company { get; set; }

class Company
  public string Id { get; set; }

Company maps to a COMPANY table (ID as PK)
CompanyExportCriteria maps to a COMPANY_EXPORT_CRITERIA table (COMPANY_ID) as key.

PS - I am using Fluent NHibernate for mapping.

+1  A: 

Here's a link to the one-to-one mapping documentation for Fluent NHibernate:

http://wiki.fluentnhibernate.org/Fluent_mapping#HasOne_.2F_one-to-one

Here's a link to the same thing for NHibernate:

http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone

You shouldn't need a composite key.

Michael Maddox
The NHibernate documentation helped, specifically the part about the "foreign" ID generator mechanism. The syntax I had to use doesn't seem like ideal fluent syntax (first off, not using a lambda for the Foreign parameter. But here is what I got to work:Id<string>("COMPANY_ID"); .GeneratedBy.Foreign("Company")
Rich