zoukankan      html  css  js  c++  java
  • ActiveRecord环境搭建和配置

    ActiveReocrd是Castle中一ORM框架,它对NHibernate做了进一步的封装。
    1.环境搭建

      a.程序集引用 (注意各程序集间版本兼容性)
        Castle.ActiveRecord.dll
        Castle.DynamicProxy2.dll
        Iesi.Connections.dll
        NHibernate.dll
        Nhibernate.ByteCode.Castle.dll
        /*
              这一项根据自己需要来选择不同的延迟加载代理工厂
              NHibernate.ByteCode.Castle.dll
              NHibernate.ByteCode.LinFu.dll
              NHibernate.ByteCode.Spring.dll
        */
      b.配置
        可以在应用程序配置文件和单独的配置文件中来进行配置,也可以通过编程方式配置
        配置项参考nhibernate hibernate.cfg.xml 
        在应用程序配置文件中配置

        <?xml version="1.0" encoding="utf-8" ?>
         <configuration>
            <configSections>
                <section name="activerecord" 
    type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler,Castle.ActiveRecord"/> </configSections> <activerecord> <config> <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <add key="connection.connection_string" value="server=.;database=study;uid=sa;pwd=sa"/> <add key="show_sql" value="true"/> <add key="proxyfactory.factory_class"
    value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" /> </config> </activerecord> </configuration>
        加载配置
          IConfigurationSource source = ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
          ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source);
     

        在xml文件中配置

     

        <?xml version="1.0" encoding="utf-8" ?>
        <activerecord>
            <config>
                <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
                <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
                <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
                <add key="connection.connection_string" value="server=.;database=study;uid=sa;pwd=sa"/>
                <add key="show_sql" value="true"/>
                <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
            </config>
        </activerecord>

        加载配置
            IConfigurationSource source = new XmlConfigurationSource("XMLFile2.xml");
            ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source);
        编程方式配置

        InPlaceConfigurationSource source = new InPlaceConfigurationSource();
        Hashtable properties = new Hashtable();
        properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
        properties.Add("dialect", "NHibernate.Dialect.MsSql2000Dialect");
        properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        properties.Add("connection.connection_string", "UID=sa;Password=19811218;Initial Catalog=ARDemo;Data Source=.");
        properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
        source.Add(typeof(ActiveRecordBase), properties);
        ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source);

  • 相关阅读:
    部署 AppGlobalResources 到 SharePoint 2010
    还原一个已删除的网站集
    使用仪表板设计器配置级联筛选器 (SharePoint Server 2010 SP1)
    File or arguments not valid for site template
    Pex and Moles Documentation
    Content Query Webpart匿名访问
    Running Moles using NUnit Console from Visual Studio
    Calling a WCF Service using jQuery in SharePoint the correct way
    Updating Content Types and Site Columns That Were Deployed as a Feature
    asp.net中判断传过来的字符串不为空的代码
  • 原文地址:https://www.cnblogs.com/heros/p/1676535.html
Copyright © 2011-2022 走看看