zoukankan      html  css  js  c++  java
  • Nhiberntae实例(操作Oracle)

    1.文件路径
    \App_Data\Entity\DEP.cs
    \App_Data\Entity\NHibernateHelper.cs(参考官方文档)
    \App_Data\Mapping\DEP.hbm.xml
    \bin\hibernate.cfg.xml
     

    2.hibernate.cfg.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 
    This template was written to work with NHibernate.Test.
    Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it 
    for your own use before compile tests in VisualStudio.
    -->
    <!-- This is the System.Data.OracleClient.dll provider for Oracle from MS -->
    <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
      <session-factory name="NHibernate.Test">
        <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
        <property name="connection.connection_string">
          User ID=kenny1;Password=123456;Data Source=orcl
        </property>
        <property name="show_sql">false</property>
        <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
        <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
        <mapping assembly="WebApplication4" />
     
      </session-factory>
    </hibernate-configuration>
     
    3.主要文件
    DEP.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Linq;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    namespace QuickStart
    {
        [Table]
        public class DEP
        {
            [Column(IsPrimaryKey = true)]
            public virtual int DEPID { get; set; }
     
            [Column]
            public virtual string Name { get; set; }
     
            public DEP()
            {
            }
     
        }
    }
     
    DEP.hbm.xml(要设为嵌入的资源和始终复制)
     
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="WebApplication4">
     
      <class name="QuickStart.DEP" table="DEP1" lazy="false">
     
        <!-- A 32 hex character is our surrogate key. It's automatically
                generated by NHibernate with the UUID pattern. -->
        <id name="DEPID">
          <column name="DEPID" not-null="true"/>
          <generator class="sequence">
            <param name="sequence">DEP1_SEQU</param>
          </generator>
     
        </id>
        
     
        <!-- A cat has to have a name, but it shouldn' be too long. -->
        <property name="Name"/>
        
       
      </class>
     
    </hibernate-mapping>
     
    4.操作代码
     
    ISession session = NHibernateHelper.GetCurrentSession();
    ITransaction tx = session.BeginTransaction();
    DEP dep = new DEP();
    dep.Name = "basic";
    session.Save(dep);
    tx.Commit();
    NHibernateHelper.CloseSession();
  • 相关阅读:
    机器学习(深度学习)
    机器学习(六)
    机器学习一-三
    Leetcode 90. 子集 II dfs
    Leetcode 83. 删除排序链表中的重复元素 链表操作
    《算法竞赛进阶指南》 第二章 Acwing 139. 回文子串的最大长度
    LeetCode 80. 删除有序数组中的重复项 II 双指针
    LeetCode 86 分割链表
    《算法竞赛进阶指南》 第二章 Acwing 138. 兔子与兔子 哈希
    《算法竞赛进阶指南》 第二章 Acwing 137. 雪花雪花雪花 哈希
  • 原文地址:https://www.cnblogs.com/kenny999/p/2309657.html
Copyright © 2011-2022 走看看