zoukankan      html  css  js  c++  java
  • 基于疑问看Nhibernate

      终于鼓起勇气再看NHibernate了,这次是带着疑问来看的,希望能够走入从类到数据库的境界。
      原本看到的那些sample都是把数据库连接信息写入app.config或者 web.config
      就在担心数据库连接信息的安全性。
      其实完全没有必要担心,我们可以在程序中进行增加配置信息,然后BuildSessionFactory
      这样就为那些webservice  remoting或者对连接信息比较敏感的C/S程序提供了帮助。
      具体代码可以看如下
     
    _nHConfiguration = new Configuration(); 

      _nHConfiguration.Properties.Add(
    "hibernate.connection.provider"
          
    "NHibernate.Connection.DriverConnectionProvider"); 

      _nHConfiguration.Properties.Add(
    "hibernate.dialect"
          
    "NHibernate.Dialect.Oracle9Dialect"); 

      _nHConfiguration.Properties.Add(
    "hibernate.connection.driver_class"
          
    "NHibernate.Driver.OracleClientDriver"); 

      _nHConfiguration.Properties.Add(
    "hibernate.connection.connection_string"
          
    string.Format( 
          Core.Configuration.Database.ConnectionStringTemplate, 
          Core.Configuration.Database.Name, 
          Core.Configuration.Database.ConnectionUsername, 
          Core.Configuration.Database.ConnectionPassword)); 

      _nHConfiguration.Properties.Add(
    "hibernate.show_sql""true"); 


      _nHConfiguration.AddAssembly(
    "ChemRex.Application"); 
      _nHConfiguration.AddAssembly(
    "ChemRex.Security"); 
      _nHConfiguration.AddAssembly(
    "ChemRex.Core"); 

      _hNSessionFactory 
    = _nHConfiguration.BuildSessionFactory();

      我们可以清楚地看到原来存放在配置文件的,统统可以在这里用代码加入。
      呵呵,对nhibernate更有信心了。
      接下去的疑问是,如何减少关联对象的冗余SQL查询。
     还有缓存的问题。

  • 相关阅读:
    推箱子(简易版)
    [LeetCode] Word Ladder II
    [LeetCode] Path Sum
    [LeetCode] Word Ladder
    DFS & BFS
    [LeetCode] Surrounded Regions
    [LeetCode] Add Binary
    [LeetCode] Plus One
    [LeetCode] Single Number II
    [LeetCode] Single Number
  • 原文地址:https://www.cnblogs.com/wildfish/p/348560.html
Copyright © 2011-2022 走看看