首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(1) | 引用(0) | 阅读2988次
O/R MAPPING-NHibernate学习笔记Source Code

数据库表的-映射XML

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
 <class name="MyCompany.MyProject.Db.PHS_LT4800_Main, MyCompany.MyProject" table="PHS_LT4800_Main">
  <id name="ID" column="ID" type="Int64">
   <generator class="identity" />
  </id>
  <property name="name" type="String(25)" column="name" />
  <property name="num" type="String(10)" column="num" />
  <property name="desce" type="String(100)" column="desce" />
  <property name="parent" type="Int32" column="parent" />
 </class>
</hibernate-mapping>


数据库表的-映射类

using System;

namespace MyCompany.MyProject.Db
{
 public class  PHS_LT4800_Main
 {
  public PHS_LT4800_Main()
  {

   }


  private System.Int64 _ID;
  public System.Int64 ID
  {
    get { return _ID; }
   set { _ID = value; }
   }

  private System.String _num;
  public System.String num
  {
    get { return _num; }
   set { _num = value; }
   }

  private System.String _desce;
  public System.String desce
  {
    get { return _desce; }
   set { _desce = value; }
   }

  private System.String _name;
  public System.String name
  {
    get { return _name; }
   set { _name = value; }
   }

  private System.Int32 _parent;
  public System.Int32 parent
  {
    get { return _parent; }
   set { _parent = value; }
   }
  }
}


NH的配置文件-APP.CFG

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
         <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
 </configSections>
 
 <nhibernate>
  <add
   key="hibernate.connection.provider"         
   value="NHibernate.Connection.DriverConnectionProvider"
  />
  <add
   key="hibernate.dialect"                     
   value="NHibernate.Dialect.MsSql2000Dialect"
  />
  <add
   key="hibernate.connection.driver_class"         
   value="NHibernate.Driver.SqlClientDriver"
  />
  <add
   key="hibernate.connection.connection_string"
   value="Server=localhost;initial catalog=phs;Integrated Security=SSPI;User id=sa;password=sfhlf;"
  />
 </nhibernate>
 <!-- This section contains the log4net configuration settings -->
 <log4net>

  <!-- Define some output appenders --> 

  <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
   
   <param name="File" value="log.txt" />
   <param name="AppendToFile" value="true" />
   <param name="RollingStyle" value="Date" />
   <param name="DatePattern" value="yyyy.MM.dd" />
   <param name="StaticLogFileName" value="true" />

   <layout type="log4net.Layout.PatternLayout,log4net">
    <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{ auth }&gt; - %m%n" />
   </layout>
  </appender>

  <!-- Setup the root category, add the appenders and set the default priority -->
  
  <root>
   <priority value="ALL" />
   <appender-ref ref="rollingFile" />
  </root>

 </log4net>
 
</configuration>


实现代码:

   Configuration cfg = new Configuration();
   cfg.AddAssembly("MyCompany.MyProject");

   ISessionFactory factory = cfg.BuildSessionFactory();
   ISession session = factory.OpenSession();
   ITransaction transaction = session.BeginTransaction();
   
   for(int i=0;i<1000;i++)
   {
    PHS_LT4800_Main pm=new PHS_LT4800_Main(); 
    pm.name ="电话sdsdf"+i.ToString();
    pm.num ="sdf"+i.ToString();
    pm.parent =1;
    session.Save(pm);
    
    }
   transaction.Commit();
   session.Close();

好像不管单条还是多条,都是2~3秒左右



字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/NHibernate2.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1107417966

2005年2月3日16:06星期四  [Dev开发] 追踪此文的RSS
rkmhjrvdma在 2008年3月23日19:48星期日 评论:
<a href="http://wakocy.com">xihaxe</a> | [url=http://zopivi.com]xonowe[/url] | [link=http://wicutu.com]xowiru[/link] | http://niripa.com | kutuke | [http://voxece.com tonasu]

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1790
在线: 19||用户: 2562 [列表]
今日:2364||到访:2671863
Rss:838496||评论:1584

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8