zoukankan      html  css  js  c++  java
  • 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/

    转载请注明:博客园

  • 相关阅读:
    软件工程概论
    软件工程概论
    JAVA
    JAVA
    C#字符补位
    C#绘图双缓冲
    C#中IP地址转换为数值的方法
    C#并行编程-并发集合
    C#委托
    C#事件(event)解析
  • 原文地址:https://www.cnblogs.com/jams742003/p/1607099.html
Copyright © 2011-2022 走看看