多表的建立 (一) DataZJ表的類和映射

 1using System;
 2using System.Collections;
 3using Iesi.Collections;
 4
 5namespace temp0704
 6{
 7    #region DataZJ
 8
 9    /// <summary>
10    /// DataZJ object for NHibernate mapped table 'DataZJ'.
11    /// </summary>
12    public class DataZJ
13    {
14        #region Member Variables
15
16        protected int _id;
17        protected long _xb;
18        protected DateTime _sr;
19        protected string _dz;
20        private ISet _user;
21
22        #endregion
23
24        #region Constructors
25
26        public DataZJ ( ) { }
27
28        public DataZJ ( long xb, DateTime sr, string dz )
29        {
30            this._xb = xb;
31            this._sr = sr;
32            this._dz = dz;
33        }
34
35        #endregion
36
37        #region Public Properties
38///這個地方對應了一個映射了,注意要寫成Iset類型,因為映射里面使用set標簽
39        public virtual ISet USZJ
40        {
41            get
42            {
43                return _user;
44            }set
45            {
46                _user = value;
47            }
48        }
49        public virtual int Id
50        {
51            get { return _id; }
52            set { _id = value; }
53        }
54
55        public virtual long Xb
56        {
57            get { return _xb; }
58            set { _xb = value; }
59        }
60
61        public virtual DateTime Sr
62        {
63            get { return _sr; }
64            set { _sr = value; }
65        }
66
67        public virtual string Dz
68        {
69            get { return _dz; }
70            set
71            {
72                if ( value != null && value.Length > 500 )
73                    throw new ArgumentOutOfRangeException("Invalid value for Dz", value, value.ToString());
74                _dz = value;
75            }
76        }
77
78
79
80        #endregion
81    }
82    #endregion
83}

 1<?xml version="1.0" encoding="utf-8" ?>
 2<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
 3  <class name="temp0704.DataZJ, temp0704" table="DataZJ">
 4    <id name="Id" type="Int32" unsaved-value="null">
 5      <column name="Meid" length="4" sql-type="intnot-null="true" unique="true" index="PK_DataZJ"/>
 6      <generator class="native" />
 7    </id>
 8    <property name="Xb" type="Int64">
 9      <column name="xb" length="8" sql-type="bigintnot-null="false"/>
10    </property>
11    <property name="Sr" type="DateTime">
12      <column name="sr" length="8" sql-type="datetimenot-null="false"/>
13    </property>
14    <property name="Dz" type="String">
15      <column name="dz" length="500" sql-type="varcharnot-null="false"/>
16    </property>
17    <set name="USZJ" table="UserZJ" lazy="true">
18      <key column="Meid"/>
19      <one-to-many class="temp0704.UserZJ, temp0704" not-found="ignore" />
20    </set>
21  </class>
22</hibernate-mapping>
23

映射的寫法
<set name="USZJ" table="UserZJ" lazy="true">
      <key column="Meid"/>
      <one-to-many class="temp0704.UserZJ, temp0704" not-found="ignore" />
</set>


posted on 2007-07-06 14:46  HB_Bill  阅读(261)  评论(0编辑  收藏  举报

导航