zoukankan      html  css  js  c++  java
  • Castle ActiveRecord学习(二)配置、引用、程序启动

    来源:http://www.cnblogs.com/zxj159/p/4082987.html

    配置数据库驱动:

    Model层引用:Castle.ActiveRecord.dll、NHibernate.dll

    Web层引用:Model、Castle.ActiveRecord-3.0.RC中的所有DLL

    Web中新增NHibernate.config配置文件:

    <?xml version="1.0" encoding="utf-8"?>
    <activerecord isWeb="true">
      <config>
        <add
          key="connection.driver_class"
          value="NHibernate.Driver.SqlClientDriver" />
        <add
          key="dialect"
          value="NHibernate.Dialect.MsSql2005Dialect" />
        <add
          key="connection.connection_string"
          value="UID=sa;Password=123456;Initial Catalog=ActiveRecord_Blog;Data Source=." />
        <add
          key="connection.provider"
          value="NHibernate.Connection.DriverConnectionProvider" />
        <add 
          key="proxyfactory.factory_class" 
          value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
      </config>
    </activerecord>
    

      

    Global.asax:加载配置文件

    protected void Application_Start(object sender, EventArgs e)
            {
                // 在应用程序启动时运行的代码
                //AuthConfig.RegisterOpenAuth();
                //RouteConfig.RegisterRoutes(RouteTable.Routes);
                InitActiveRecord();
            }
    
            //Castle Record Register Model
            private void InitActiveRecord()
            {
                try
                {
                    //加载配置文件
                    string NHibernateFilePath = Server.MapPath("~/NHibernate.config");
                    XmlConfigurationSource source = new XmlConfigurationSource(NHibernateFilePath);
                    //注册数据模型
                    ActiveRecordStarter.Initialize(source, typeof(Models.UserInfo), typeof(Models.ThemeInfo), typeof(Models.CommentInfo), typeof(Models.CategoryInfo));
                }
                catch (Exception)
                {
                    throw;
                }
            }
    

      

  • 相关阅读:
    数据攻略●R语言自述
    测试实例
    xml反射
    过滤器
    使用s标签来进行简单的表格配置
    将Spring、Hibernate、Struts2连接起来
    Spring容器
    初见Spring框架
    Spring框架的AOP
    Hibernate里面的几个方法
  • 原文地址:https://www.cnblogs.com/xsj1989/p/5306980.html
Copyright © 2011-2022 走看看