이 글은 기계 번역의 미러 문서이며, 원본 기사로 바로 이동하려면 여기를 클릭해 주세요.

보기: 17312|회답: 0

[출처] .net에서 Nhibernate를 위한 세 가지 구성 방법이 있습니다

[링크 복사]
게시됨 2016. 8. 8. 오후 1:17:51 | | |

1 App.config 구성:

<?XML version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <섹션 이름="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" requirePermission="false"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider,NHibernate</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">
        <!--Server=(local); 초기 카탈로그=nhibernate; 통합 보안=SSPI-->
        database='nhibernate'; 서버=.; uid='sa'; PWD='sa';
      </property>
      <property name="adonet.batch_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactory, NHibernate.ByteCode.LinFu</property>
    </session-factory>
</hibernate-configuration>
----------------------------------------------------------------------------------------------------------------------

#region 2 . App.config 구성
            Configuration config = new Configuration(). AddAssembly("Test.Model");        

        공장 = 구성. 빌드세션팩토리();
          세션 = 공장. OpenSession();
#endregion

--------------------------------------------------------------------------------------------------------------------------
</configuration>

2 Web.config 구성 배치할 바이트 위치 기록

<!--비 -->
   <섹션 이름="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
   <!--하이베네이트-->
</configSections>
<!--하이베네이트-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate'; 서버=.; uid='sa'; PWD='sa'; </property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactory, NHibernate.ByteCode.LinFu</property>
   </session-factory>
</hibernate-configuration>
<!--하이베네이트-->
<appSettings/>

---------------------------------------------------------------------------------------------------------



#region 2. web.config를 사용해 다음을 설정하세요

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model");
        공장 = 구성. 빌드세션팩토리();
        세션 = 공장. OpenSession();

        #endregion

-----------------------------------------------------------------------------------------------------------

3 NHibernate.cfg.xml 구성:

<?XML version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-mapping-2.2">
<session-factory xmlns="urn:nhibernate-configuration-2.2">
    <!-- 특성 -->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate'; 서버=.; uid='sa'; PWD='sa'; </property>
    <property name="show_sql">true</property>
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactory, NHibernate.ByteCode.LinFu</property>
    <property name="use_outer_join">true</property>
    <!-- 매핑 파일 -->
    <mapping assembly="Test.Model" />
</session-factory>
</hibernate-configuration>

-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------

   #region 3. NHibernate.cfg.xml 구성 활용

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        구성. Configure(@"C:\문서 및 설정\관리자\데스크톱\텍스트\NHibernateTest\WebSite1\NHibernate.cfg.xml");
        공장 = 구성. 빌드세션팩토리();
        세션 = 공장. OpenSession();
        #endregion



4 다음과 같이 MyConfiguration.cs 구조를 만드세요:



public static NHibernate.Cfg.Configuration GetConfig()
    {

      
        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        구성. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        구성. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
        구성. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; 서버=.; uid='sa'; PWD='sa'; ");
        구성. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate");
        구성. SetProperty("hibernate.use_outer_join", "true");
        구성. SetProperty("hibernate.show_sql", "false");
        구성. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
        구성. AddAssembly("Test.Model");
        설정 반환;
      
    }



------------------------------------------------------------------------------------------------------------------------------

#region 4. MyConfiguration.cs 구성 사용

        NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Use MyConfiguration.cs
        공장 = 구성. 빌드세션팩토리();
        factory = MyConfiguration.GetConfig(). 빌드세션팩토리();
        세션 = 공장. OpenSession();
        #endregion




이전의:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...
다음:섹션 문이 없어서 구성 섹션 "XXX"를 읽을 수 없습니다
면책 조항:
Code Farmer Network에서 발행하는 모든 소프트웨어, 프로그래밍 자료 또는 기사는 학습 및 연구 목적으로만 사용됩니다; 위 내용은 상업적 또는 불법적인 목적으로 사용되지 않으며, 그렇지 않으면 모든 책임이 사용자에게 부담됩니다. 이 사이트의 정보는 인터넷에서 가져온 것이며, 저작권 분쟁은 이 사이트와는 관련이 없습니다. 위 내용은 다운로드 후 24시간 이내에 컴퓨터에서 완전히 삭제해야 합니다. 프로그램이 마음에 드신다면, 진짜 소프트웨어를 지원하고, 등록을 구매하며, 더 나은 진짜 서비스를 받아주세요. 침해가 있을 경우 이메일로 연락해 주시기 바랍니다.

Mail To:help@itsvse.com