NHibernate学习

 
 
 

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

NHibernate资源

NHibernate资源现在已经比较多了,但是大部分都是英文了,这里我仅仅挑选几个站点。

NHibernate官方主页:http://www.nhibernate.org/(英文)

NHibernate社区:http://www.nhforge.org/(英文)

NHibernate参考文档2.0.0:http://nhforge.org/doc/nh/en/(英文)

NHibernate之夏系列录像教程:http://www.summerofnhibernate.com/(英文)

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

一、数据访问层配置:

<?xml version="1.0" encoding="utf-8"?>
<
hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<
session-factory>

<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<
property name="connection.connection_string">
Data Source=."SQLEXPRESS;Initial Catalog=NHibernateSample;
Integrated Security=True;Pooling=False
</property>
<
property name="adonet.batch_size">10</property>
<
property name="show_sql">true</property>

<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<
property name="use_outer_join">true</property>
<
property name="command_timeout">10</property>
<
property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>

<mapping assembly="DomainModel"/>

 </session-factory>
</
hibernate-configuration>

将复制到输出目录设置为:永远赋值

 

二、映射文件

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="LearnHibernate.Model"

namespace="LearnHibernate.Model">

<class name="LearnHibernate.Model.User, LearnHibernate.Model" table="Users">

<id name="Id" type="Int32" unsaved-value="null">

<column name="id" length="4" sql-type="int" not-null="true" unique="true" index="PK_user"/>

<generator class="native" />

</id>

<property name="Name" type="String">

<column name="name" length="50" sql-type="nvarchar" not-null="false"/>

</property>

<property name="Password" type="String">

<column name="password" length="50" sql-type="nvarchar" not-null="false"/>

</property>

</class>

</hibernate-mapping>

注:将生成操作设置为:嵌入式资源

 

三、持久化数据

规则

  • NHibernate使用属性的getter和setter来实现持久化。
  • 属性可设置为public、internal、protected、protected internal或private

注意:

NHibernate默认使用代理功能,要求持久化类不是sealed的,而且其公共方法、属性和事件声明为virtual。在这里,类中的字段要设置为virtual,否则出现“failed: NHibernate.InvalidProxyTypeException : The following types may not be used as proxies: DomainModel.Entities.Customer: method get_CustomerId should be virtual,method set_CustomerId should be virtual”异常。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值