0

私は2つのクラスを持っています:

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; }
}

Entry オブジェクトの Code 子プロパティ (null にすることができ、Codes テーブルの外部キー「EntryId」によってリンクされている) を nhibernate に自動的にロード/保存させたいのですが、マッピングがわかりません。hibernate.org のドキュメントが現在ロードされていないので、誰かが以下のマッピングで正しい方向に向けることができますか?

  <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>
4

1 に答える 1

0

この記事は可能性を非常によく説明していると思います: http://ayende.com/Blog/archive/2009/04/19/nhibernate-mapping-ltone-to-onegt.aspx

双方向性を「シミュレート」する必要はありませんが、それは簡単に省略できます。

于 2009-07-24T07:14:14.667 に答える