zoukankan      html  css  js  c++  java
  • NHibernate学习总结:(一)NHibernate的使用和配置

    本文来源:http://www.cnblogs.com/virusswb/archive/2010/01/08/1642402.html

    在数据库中新建如下图的数据库结构,数据库的名称为NHibernate,包括Customer、Order、Product、OrderProduct四张表,其中的Id为int,不是自增列,其他列是varchar(50),Cost为float具体结构如下图

    NHibernate1.1

    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>

     

    今天只是一个简单的内容读取。

    NHibernate1.2

    Technorati 标签: NHibernate

    代码可以从http://nhibernatedemo.codeplex.com/下载。

  • 相关阅读:
    40款不容错过的个人摄影设计作品集网站
    Google的全新在线地图API演示网站 More than a map
    绝对不容错过的超棒动物瞬间抓拍摄影作品
    超全超实用的Javascript类库和jQuery插件大全之一:Web印刷排版
    Java中方法重写和方法重载的6个区别?
    面试突击15:说一下HashMap底层实现?及元素添加流程?
    查询 MySQL 字段注释的 5 种方法!
    剑指Offer补充
    Cracking the Coding Interviewch11 | System Design and Memory Limits
    Cracking the Coding Interview – ch16,17,18
  • 原文地址:https://www.cnblogs.com/weekend001/p/1642648.html
Copyright © 2011-2022 走看看