views:

209

answers:

1

I have two classes:

public class Code
{
    public virtual Guid CodeId { get; set; }
    public virtual string CodeValue { get; set; }
    public virtual Guid EntryId { get; set; }
}

public class Entry
{
    public virtual Guid EntryId { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual string Address { get; set; }
    public virtual string Address2 { get; set; }
    public virtual string City { get; set; }
    public virtual string State { get; set; }
    public virtual string Zip { get; set; }
    public virtual string Email { get; set; }
    public virtual string Phone { get; set; }
    public virtual string IpAddress { get; set; }
    public virtual DateTime BirthDate { get; set; }
    public virtual DateTime Created { get; set; }
    public virtual bool OptIn { get; set; }
    public virtual Code Code { get; set; }
}

I want nhibernate to automatically load/save the Code child property of the Entry object (which can be null and is linked by a foreign key "EntryId" in the Codes table), but I cannot figure out the mapping. The documentation at hibernate.org isn't loading for me right now, so could someone point me in the right direction with the mappings below?

  <class name="Code" table="Codes">
    <id name="CodeId">
      <generator class="guid.comb"/>
    </id>
    <property name="CodeValue" />
    <property name="EntryId"
  </class>

  <class name="Entry" table="Entries">
    <id name="EntryId">
      <generator class="guid.comb"/>
    </id>
    <property name="FirstName" />
    <property name="LastName" />
    <property name="Address" />
    <property name="Address2" />
    <property name="City" />
    <property name="State" />
    <property name="Zip" />
    <property name="Email" />
    <property name="Phone" />
    <property name="BirthDate" />
    <property name="OptIn" />
    <property name="IpAddress" />
    <property name="Created" />    
  </class>
A: 

I believe this article describes the possibilities very well: http://ayende.com/Blog/archive/2009/04/19/nhibernate-mapping-ltone-to-onegt.aspx

You just don't need to "simulate" the bidirectionality, but that's easy to leave out.

asgerhallas