Your one to one mapping in Person must be like this (if you say one person 
only must have one contact! ): 
<one-to-one name="Contact" cascade="all" /> --> if your contact class in 
same assembly you dont have to  specify namespace or assembly name 

and in entity class
public virtual Contact Contact
        {
            get { return m_contact; }
            set { m_contact = value; }
        }
it works for me in NH 3.3.1

if you want to make many to one relationship and if you have no record 
leave relational entity as null this example helps you
in Person Mapping File
  <many-to-one name="Contact" class="FullNameSpace.Contact,AssemblyName"
               column="ContactId" not-null="false" cascade="all" 
not-found="ignore" lazy="proxy"/>

13 Aralık 2012 Perşembe 20:54:55 UTC+2 tarihinde Michael Schuld yazdı:
>
> I have two entities: Person and Contact.
>
> These have a one to one relationship (in the database each has an Id 
> foreign key to the other). I cannot use the one to one mapping in 
> NHibernate because of this bug<https://nhibernate.jira.com/browse/NH-2534> 
> causing 
> a lot of very terrible N+1 issues so instead have mapped the association as 
> many-to-one from both directions:
>
> <many-to-one name="Contact" class="Contact, Common" cascade="all">
> <column name="ContactId" sql-type="int" not-null="true" 
> index="FK_Person_Contact"/>
> </many-to-one>
>
> <many-to-one name="Person" class="Person, Common" cascade="all">
> <column name="PersonId" sql-type="int" not-null="true" 
> index="FK_Contact_Person"/>
> </many-to-one>
>
> When trying to save a new set of these items, I am getting the common null 
> or transient error that always seems to be related to people not setting 
> the cascade property in their mapping. As you can see I have cascade set to 
> all. Is there something about doing this bi-directional many to one that 
> causes this issue to occur. I would like to leave the not-null="true" on 
> both sides of the relationship if possible as no record of either type can 
> exist in the database without the other.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/MgNy99X6CHwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to