zoukankan      html  css  js  c++  java
  • NHibernate插入数据的列子

    话不多说,直接贴源码:1.Model:public virtual int LogonID { get; set; }
           public virtual string Name1 { get; set; }
           public virtual string Password1 { get; set; }
           public virtual string EmailAddress { get; set; }
           public virtual DateTime LastLogon { get; set; }

    2.User.hbm.xml:<?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <!--1.2版的NHibernate为2.2-->
      <class name="Model.User,Model" table="Users2">
        <!--name的前面是命名空间+类命,后面是类库名称-->
        <id name="LogonID" column="LogonID" unsaved-value="0">
          <generator class="assigned"/>
        </id>
        <property name="Name1" column="Name1" ></property>
        <property name="Password1" column="Password1"  ></property>
        <property name="EmailAddress" column="EmailAddress" ></property>
        <property name="LastLogon" column="LastLogon"></property>
      </class>
    </hibernate-mapping>

    3.web.config配置下的cs后台代码:NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            cfg.AddAssembly("Model");
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            User newUser = new User();
            newUser.LogonID =35;
            newUser.Name1 = "李四";
            newUser.Password1 = "1234";
            newUser.EmailAddress = "131552";
            newUser.LastLogon =DateTime.Now;
            session.Save(newUser);
            session.Flush();

    4.oracle10g的web.config配置文件:<configSections>
        <section
        name="hibernate-configuration"
        type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
    />
      </configSections>
      <!-- Add this element -->
      <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <session-factory>
          <property name="connection.connection_string">
            User ID=CSU;Password=123456;Data Source=CSUGRA
          </property>
          <property name="show_sql">false</property>
          <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
          <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
          <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
          <property name="hbm2ddl.auto">update</property>
          <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
          <mapping assembly="Model"/>
        </session-factory>
      </hibernate-configuration>

    5.最后来张贴图:

    STUDTY HARD FOR .NET
  • 相关阅读:
    Redis知识梳理(1)当我们谈到双写一致性的时候,我们在谈什么?
    多线程知识梳理(4),当我们谈到volatile的时候,我们在谈什么?
    多线程知识梳理(3),当我们谈到CAS的时候,我们在谈什么?
    多线程知识梳理(2),当我们谈到synchronized关键字的时候,我们在谈什么?
    多线程知识梳理(1):当我们谈到指令乱序的时候,在谈什么?
    LeetCode刷题记录本
    “退格”转义字符使用实例
    “逻辑异或”进行数值交换的过程分析
    ConcurrentHashMap源码走读
    Netty如何监控内存泄露
  • 原文地址:https://www.cnblogs.com/zhishuru/p/2508157.html
Copyright © 2011-2022 走看看