NHibernate学习总结:(一)NHibernate的使用和配置
2010-01-08 22:06
585 查看
本文来源:/article/4661723.html
在数据库中新建如下图的数据库结构,数据库的名称为NHibernate,包括Customer、Order、Product、OrderProduct四张表,其中的Id为int,不是自增列,其他列是varchar(50),Cost为float具体结构如下图
1、实体类代码
2、对应的映射文件Customer.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernateSample.Domain"
namespace="NHibernateSample.Domain.Entities">
<class name="NHibernateSample.Domain.Entities.Customer, NHibernateSample.Domain" table="Customer" lazy="false">
<id name="Id" column="CustomerId" type="System.Int32">
<generator class="assigned"></generator>
</id>
<property name="Version" column="Version"/>
<property name="Firstname" column="Firstname"/>
<property name="Lastname" column="Lastname"/>
</class>
</hibernate-mapping>
3、web.config中的配置
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=SHIWB\SQL2005DEV;Database=NHibernate;User ID=as;Password=123456;
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">60</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="NHibernateSample.Domain"/>
</session-factory>
</hibernate-configuration>
</configuration>
今天只是一个简单的内容读取。
Technorati 标签: NHibernate
代码可以从http://nhibernatedemo.codeplex.com/下载。
在数据库中新建如下图的数据库结构,数据库的名称为NHibernate,包括Customer、Order、Product、OrderProduct四张表,其中的Id为int,不是自增列,其他列是varchar(50),Cost为float具体结构如下图
1、实体类代码
public class Customer { public virtual int Id { get; set; } public virtual string Firstname{get;set;} public virtual string Version { get; set; } public virtual string Lastname { get; set; } }
2、对应的映射文件Customer.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernateSample.Domain"
namespace="NHibernateSample.Domain.Entities">
<class name="NHibernateSample.Domain.Entities.Customer, NHibernateSample.Domain" table="Customer" lazy="false">
<id name="Id" column="CustomerId" type="System.Int32">
<generator class="assigned"></generator>
</id>
<property name="Version" column="Version"/>
<property name="Firstname" column="Firstname"/>
<property name="Lastname" column="Lastname"/>
</class>
</hibernate-mapping>
3、web.config中的配置
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=SHIWB\SQL2005DEV;Database=NHibernate;User ID=as;Password=123456;
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">60</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="NHibernateSample.Domain"/>
</session-factory>
</hibernate-configuration>
</configuration>
今天只是一个简单的内容读取。
Technorati 标签: NHibernate
代码可以从http://nhibernatedemo.codeplex.com/下载。
相关文章推荐
- NHibernate学习总结:(一)NHibernate的使用和配置
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- [学习总结]8、android 自定义控件 使用declare-styleable进行配置属性(源码角度)
- [学习总结]9、Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- JNDI学习总结(3)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(三)——Tomcat下使用Druid配置JNDI数据源
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(3)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(4)——Tomcat下使用Druid配置JNDI数据源
- Solr学习总结(八)IK 中文分词的配置和使用
- JNDI学习总结(二)——Tomcat下使用C3P0配置JNDI数据源
- JNDI学习总结(三)——Tomcat下使用Druid配置JNDI数据源
- 【学习总结】UNIX网络编程使用源码配置
- MyBatis学习总结一 —— MyBatis的使用步骤及配置
- JNDI学习总结(三)——Tomcat下使用Druid配置JNDI数据源
- JavaWeb学习总结(四十八)——模拟Servlet3.0使用注解的方式配置Servlet