一> 将download的Nhibernate 解压,根据项目实际将其bin文件下的相关Dll文件,拷贝到Asp.net项目中Bin文件夹下;
二> 打开web.cofig文件 ,在<configuration>下进行Nhibernate 配置
三> 编写需要持久化的类User
四> 当然先要建好数据表users;构建持久化对象属性的映射文件User.hbm.xml (将类属性映射为数据表users的字段),注意如是用vs.net 2003编译,则映射文件User.hbm.xml的生成操作要选为"嵌入的资源"
二> 打开web.cofig文件 ,在<configuration>下进行Nhibernate 配置
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add
key="hibernate.show_sql"
value="true"
/>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=127.0.0.1;initial catalog=UserTest;User id =sa;Password="
/>
</nhibernate>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add
key="hibernate.show_sql"
value="true"
/>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=127.0.0.1;initial catalog=UserTest;User id =sa;Password="
/>
</nhibernate>
三> 编写需要持久化的类User
四> 当然先要建好数据表users;构建持久化对象属性的映射文件User.hbm.xml (将类属性映射为数据表users的字段),注意如是用vs.net 2003编译,则映射文件User.hbm.xml的生成操作要选为"嵌入的资源"
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Web.User, Web" table="users">
<id name="Id" column="LogonID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="UserName" column="Name" type="String" ></property>
<property name="Password" column="Password" type="String" ></property>
<property name="EmailAddress" column="EmailAddress" type="string" ></property>
<property name="LastLogon" column="LastLogon" type="DateTime"></property>
</class>
</hibernate-mapping>
五> cs文件利用Nhibernate 的API<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Web.User, Web" table="users">
<id name="Id" column="LogonID" type="Int32" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="UserName" column="Name" type="String" ></property>
<property name="Password" column="Password" type="String" ></property>
<property name="EmailAddress" column="EmailAddress" type="string" ></property>
<property name="LastLogon" column="LastLogon" type="DateTime"></property>
</class>
</hibernate-mapping>