• castle .net之初级(一)简单示例


    配置方法:

    (一)配置文件

    1单独的配置文件

    MsSqlConfigurationSource.xml(用于配置mssql2000

    <?xml version="1.0" encoding="utf-8" ?>

    <activerecord>

      <config>

        <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />

        <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />

        <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />

        <add key="hibernate.connection.connection_string" value="Data Source=.;Initial Catalog=selftest;UID=sa;Password=123" />

      </config>

    </activerecord>

    2Webconfig中的配置

    <config>

          <add key="hibernate.connection.driver class" value="NHibernate.Driver.SqlClientDriver"/>

          <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect"/>

          <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>

          <add key="hibernate.connection.connection_string" value="ConnectionString = ${NorthWind}"/>

          <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>

        </config>

    (二)初始化

    Application_Start事件中初始化。

    1,单独的文件:

    Castle.ActiveRecord.Framework.Config.XmlConfigurationSource source = new Castle.ActiveRecord.Framework.Config.XmlConfigurationSource(Server.MapPath("MsSqlConfigurationSource.xml"));

    Castle.ActiveRecord.ActiveRecordStarter.Initialize(source,typeof(Customer));

    2,配置文件中

    Castle.ActiveRecord.Framework.IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as Castle.ActiveRecord.Framework.IConfigurationSource;

    Castle.ActiveRecord.ActiveRecordStarter.Initialize(typeof(Users).Assembly, source);

    (三)实体类

    [ActiveRecord("Customer")]//表名

    public class Customer : ActiveRecordBase

    {

        public Customer()

        {

     

        }

     

        private int _unid;

        private string _FirstName;

        private string _LastName;

        [PrimaryKey(PrimaryKeyType.Assigned,"CustomerId")]

        public int Unid

        {

            get { return _unid; }

            set { _unid = value; }

        }

        [Property("FirstName")]

        public string FirstName

        {

            get { return _FirstName; }

            set { _FirstName = value; }

        }

        [Property("LastName")]

    public string LastName

    {

            get { return _LastName; }

            set { _LastName = value; }

        }

     

        public static IList FindAll()

        {

            return (IList)FindAll(typeof(Customer));

        }

     

    }

    (四)调用

    Customer.FindAll();

     

    更多详细内容请参见:http://terrylee.cnblogs.com/archive/2006/04/03/365762.html

     

    博客园大道至简

    http://www.cnblogs.com/jams742003/

    转载请注明:博客园

  • 相关阅读:
    POJ-1947 Rebuilding Roads (树形DP+分组背包)
    HDU-1011 Starship Troopers (树形DP+分组背包)
    POJ-1155 TELE (树形DP+分组背包)
    HDU-1520 Anniversary party(树形DP)
    HDU-2196 Computer (树形DP)
    HDU-1561 The more, The Better (树形DP+分组背包)
    HDU-3853 LOOPS(概率DP求期望)
    POJ 1182(权值并查集,向量?)
    HDU 3038(权值并查集)
    POJ 1733(边带权并查集+离散化)
  • 原文地址:https://www.cnblogs.com/jams742003/p/1607028.html
Copyright © 2020-2023  润新知