Castle.ActiveRecord 使用快速上手教程

1. 创建一个名为SimpleBBS的网站项目,并引用Castle.ActiveRecord相关的程序集,列表如下:
 Castle.ActiveRecord.dll
 Castle.Core.dll
 Castle.Components.Validator.dll
 Castle.DynamicProxy.dll
 下面几个在扩展依赖文件夹中
 NHibernate.dll
 Iesi.Collections.dll
 log4net.dll

2. 创建数据结构

3. 创建类
 ActiveRecordBase<>
 ActiveRecord
 PrimaryKey
 Property
    添加关联

4. 创建配置文件 MyConfig.xml

<? 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.MsSql2005Dialect"   />
        
< add
            
key ="hibernate.connection.provider"
            value
="NHibernate.Connection.DriverConnectionProvider"   />
        
< add
            
key ="hibernate.connection.connection_string"
            value
="server=srv-devdbhost;uid=sa;pwd=Abcd1234;database=MGP_TestDB;"   />
    
</ config >
</ activerecord >



 

5. 创建Global.asax, 在 Application_Start 事件中加入:
        XmlConfigurationSource source = new XmlConfigurationSource("MyConfig.xml");
        ActiveRecordStarter.Initialize(source, typeof(ActiveRecordBase));
    引用:
        using Castle.ActiveRecord;
        using Castle.ActiveRecord.Framework.Config;

 

 


 

你可能感兴趣的:(ActiveRecord)