文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Castle.ActiveRecord的ProxyFactory配置

Castle.ActiveRecord的ProxyFactory配置

时间:2010-11-24  来源:Bēniaǒ

 

  ActoiveRecord的配置文件有了明显的变化,需要配置ProxyFactory才能完成持久化操纵,详细配置如下:

  <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=SQL05;Initial Catalog=testdb;uid=sa;pwd=12345;" />
      <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
    </config>
  </activerecord>

 

  其他的使用基本上没有变化,下面是一个ORM的对象配置。

[ActiveRecord("UserInfo")]
public class UserInfo : ActiveRecordBase<UserInfo>
{
    [PrimaryKey(PrimaryKeyType.Identity, "ID")]
    public int ID { get; set; }

    [Property("Sex", Length = 50)]
    public string Sex { get; set; }

    [Property("Name", NotNull = true)]
    public string Name { get; set; }
}

 

 

  初始化配置也还是和以前的版本使用方式一样的,支持单个对象、多个对象、单个程序集、多个程序集等等不同方式的关系映射对象进行初始化。

protected void Application_Start(object sender, EventArgs e)
{
    IConfigurationSource source = ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
    //ActiveRecordStarter.Initialize(source, typeof(Entity.UserInfo));
    ActiveRecordStarter.Initialize(Assembly.Load("Entity"), source);
}

  

  由于关系映射对象继承于ActiveRecordBase<T>泛型版本,因此可以直接基于关系映射对象使用数据持久化操纵行为,和老版本的使用方式是一样的。

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        UserInfo info = new UserInfo();
        info.Name = "zhangsan";
        info.Sex = "男";
        //插入info数据到数据库中所映射的关系表
        info.Create();
    }
}

 

   至于ProxyFactory的具体作用暂时没有深入研究,也不知道AR为什么会在新版本中添加这个功能,我想应该是想通过NHibernate对Castle的AR进行某些控制,暂时没有时间研究,期待有研究过的朋友分享,谢谢。

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载