答案: /*
作者:飞鹰
ASP酷技术资讯网(www.ASPCool.com)版权所有,如转载,请保留此信息.
*/
终于使用NHibernate作为项目研究的ORM框架,这次研究只是为了证明一件事,那就是使用ORM后可以提高程序的开发效率和优化程序的结构。
由于CRUD都可以实现了,所以,我就参照张老三的文章来做One-To-Many的例子。这里我使用SQL Server自带的NorthWind中的两个表Customers,Orders来做例子,我把Customers类作为父类,Orders类作为子类。
我们先用Cool Coder生成XML文件和C#代码,再用C#2VB转换器把C#代码转变成VB代码(为什么要转来转去呢?等过几天有空了,我升级Cool Coder,使之也可以生成VB代码,先临时凑合着用吧!)。稍作修改后就可以得到下面的内容。
先看Customers的映射信息:
xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Customers, AssemblyName" table="Customers">
<id name="CustomerID" column="CustomerID" type="String(5)">
<generator class="assigned" />
id>
<set name="Orders" inverse="true" lazy="true">
<key column="CustomerID" />
<one-to-many class="Orders, AssemblyName " />
set>
<property name="CompanyName" type="String(40)" column="CompanyName" />
<property name="ContactName" type="String(30)" column="ContactName" />
<property name="ContactTitle" type="String(30)" column="ContactTitle" />
<property name="Address" type="String(60)" column="Address" />
<property name="City" type="String(15)" column="City" />
<property name="Region" type="String(15)" column="Region" />
<property name="PostalCode" type="String(10)" column="PostalCode" />
<property name="Country" type="String(15)" column="Country" />
<property name="Phone" type="String(24)" column="Phone" />
<property name="Fax" type="String(24)" column="Fax" />
class>
hibernate-mapping>
Customers类的代码如下:
Imports System
Public Class Customers
Public Sub New()
End Sub 'New
Dim m_orderList As IDictionary = New Hashtable
'*
'* Property OrderList ( IDictionary)
'*
Public Property Orders() As IDictionary
Get
Return m_orderList
End Get
Set(ByVal Value As IDictionary)
m_orderList = Value
End Set
End Property
Private _Region As System.String
Public Property [Region]() As System.String
Get
Return _Region
End Get
Set(ByVal Value As System.String)
_Region = Value
End Set
End Property
Private _PostalCode As System.String
Public Property PostalCode() As System.String
Get
Return _PostalCode
End Get
Set(ByVal Value As System.String)
_PostalCode = Value
End Set
End Property
Private _Fax As System.String
Public Property Fax() As System.String
Get
Return _Fax
End Get
Set(ByVal Value As System.String)
_Fax = Value
End Set
End Property
Private _ContactName As System.String
Public Property ContactName() As System.String
Get
Return _ContactName
End Get
Set(ByVal Value As System.String)
_ContactName = Value
End Set
End Property
Private _City As System.String
Public Property City() As System.String
Get
Return _City
End Get
Set(ByVal Value As System.String)
_City = Value
End Set
End Property
Private _CustomerID As System.String
Public Property CustomerID() As System.String
Get
Return _CustomerID
End Get
Set(ByVal Value As System.String)
_CustomerID = Value
End Set
End Property
Private _Address As System.String
Public Property Address() As System.String
上一个:ASP.NET Session 详解
下一个:ASP.NET 2.0,无刷新页面新境界!