• castle .net之初级(一).net2.0,.net3.0


    (一)http://www.castleproject.org/castle/download.html下载ActiveRecord 2.0

    (二)独立的配置文件MsSqlConfigurationSource.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.MsSql2000Dialect" />

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

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

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

      </config>

    </activerecord>

    (三)添加引用

     

    (四)Start

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

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

     

    (五)实体类(从泛型基类派生)

    using System.Collections;

    using Castle.ActiveRecord;

    using Castle.ActiveRecord.Queries;

     

     

    [ActiveRecord("Customer")]

    public class Customer : ActiveRecordBase<Customer>

    {

        public Customer()

        {

          

        }

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

        public int Unid { get; set; }

     

        [Property("FirstName")]

        public string FirstName { get; set; }

     

        [Property("LastName")]

        public string LastName { get; set; }

     

        public static IList FindAll()

        {

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

        }

     

        public static IList<Customer> ShowList()

        {

            SimpleQuery<Customer> q = new SimpleQuery<Customer>(@"from Customer");

            return q.Execute();

        }

    }

    (六)测试

    博客园大道至简

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

    转载请注明:博客园

  • 相关阅读:
    HTTP POST GET 本质区别详解< Reprinted>
    Java的反射机制
    简单的KKL诊断线~~~自己在家都可以制作obd诊断接口了 ~~
    URL-编码窗体数据无效
    没有对“C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files”的写访问权限
    ARM中的---汇编指令
    allegro中原理图和pcb中元件的交互
    运算放大器
    电流表接法
    一款单端反激开关电源的设计
  • 原文地址:https://www.cnblogs.com/jams742003/p/1607099.html
Copyright © 2020-2023  润新知