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

简介: (一)http://www.castleproject.org/castle/download.html下载ActiveRecord 2.0 (二)独立的配置文件MsSqlConfigurationSource.

(一)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/

转载请注明:博客园

目录
相关文章
|
C# 数据安全/隐私保护 开发者
『.NET』.NET 中常用的AOP框架——Castle
📣读完这篇文章里你能收获到 - AOP概念介绍 - 结合具体代码讲解.NET项目接入Castle
250 0
『.NET』.NET 中常用的AOP框架——Castle
|
调度 容器 前端开发
|
Web App开发 JavaScript 前端开发
|
网络协议 网络架构 容器
castle .net之初级(一)简单示例
配置方法: (一)配置文件 (1)单独的配置文件 MsSqlConfigurationSource.xml(用于配置mssql2000)                     (2)Webconfig中的配置                                   (二)初始化 在Application_Start事件中初始化。
639 0
|
前端开发 .NET 开发框架
Asp.net Mvc中MVCContrib中无法使用Castle的发解决方案
在使用Asp.net Mvc MVCContrib 0.0.1.91中的Castle时会出现No component for key Home was found这样的错误 错误解决方法如下: 下载MvcContrib源代码,更改MvcContrib.
749 0
|
前端开发 .NET 开发框架
Asp.net Mvc Framework 十二 Castle扩展
由于Monorail是.net下MVC的先驱所以 Asp.net MVC理所当然要支持老的Castle用户 在Asp.net MVC扩展包中就提供了对Castle的支持与兼容 虽然这个扩展还有很多BUG与不足,但已从其中窥见Asp.
764 0