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/下载。

  • 相关阅读:
    C#里的async和await的使用
    解决 .NET CORE3.0 MVC视图层不即时编译
    【转】CSS实现自适应分隔线的N种方法
    iscrolljs 看API 回顾以前开发中失误
    自由了-和过去说再见
    js 性能基准测试工具-告别可能、也许、大概这样更快更省
    dom事件不求甚解,色解事件捕获和冒泡
    百度mobile UI组件GMU demo学习1-结构和初始化
    自己收集原生js-2014-2-23
    如何在电脑上测试手机网站(补充)和phonegap
  • 原文地址:https://www.cnblogs.com/weekend001/p/1642648.html
Copyright © 2011-2022 走看看