2009-07-23 11 views
0

J'ai deux classes:parent NHibernate/enfant un à un mappage

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

Je veux NHibernate charger/enregistrer automatiquement la propriété de l'enfant Code de l'objet d'entrée (qui peut être nul et est lié par une clé étrangère "EntryId" dans la table Codes), mais je n'arrive pas à comprendre le mappage. La documentation sur hibernate.org ne se charge pas pour moi en ce moment, donc quelqu'un pourrait-il me pointer dans la bonne direction avec les mappings ci-dessous?

<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> 
+0

http://www.nhforge.org/doc/nh/en/index.html;) – asgerhallas

+0

C'est un lien vers un qui n'est pas en panne maintenant. Section 5.1.11. – asgerhallas

+0

Cela m'a conduit à quelque chose qui fonctionne en utilisant ICollection et en établissant une relation un-à-plusieurs, mais je ne suis toujours pas sûr de savoir comment faire un one-to-one avec une clé étrangère sur la table enfant. – Chris

Répondre

Questions connexes