日期:2014-05-18  浏览次数:20452 次

Nhibernate one-to-one映射
Person   .cs

using   System;
using   System.Collections.Generic;
using   System.Text;

namespace   test4
{
        public   class   Person
        {

                public   Person()
                {
                }

                public   int   PersonId
                {
                        get   {   return   parentId;   }
                        set   {   parentId   =   value;   }
                }

                public   string   Name
                {
                        get   {   return   name;   }
                        set   {   name   =   value;   }
                }

                public   Employee   Employee
                {
                        get   {   return   employee;   }
                        set   {   employee   =   value;   }
                }

                private   int   parentId;
                private   string   name;
                private   Employee   employee;//=new   Employee();

        }   //class   Person

}


Person.hbm.xml:

<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<hibernate-mapping   xmlns= "urn:nhibernate-mapping-2.0 ">
    <class   name= "test4.Person,   test4 "   table= "Person ">
        <id   name= "PersonId "   column= "person_id "   type= "Int32 "   unsaved-value= "0 ">
            <generator   class= "identity "   />
        </id>
        <property   name= "Name "   column= "Name "   type= "String "/>
            <one-to-one  
          name= "Employee "  
          cascade= "all "
          class= "test4.Employee,   test4 "
    &n