多表的建立 (一) DataZJ表的類和映射
1
using System;
2
using System.Collections;
3
using Iesi.Collections;
4
5
namespace 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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

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="int" not-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="bigint" not-null="false"/>
10
</property>
11
<property name="Sr" type="DateTime">
12
<column name="sr" length="8" sql-type="datetime" not-null="false"/>
13
</property>
14
<property name="Dz" type="String">
15
<column name="dz" length="500" sql-type="varchar" not-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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

映射的寫法
<set name="USZJ" table="UserZJ" lazy="true">


</set>