zoukankan      html  css  js  c++  java
  • 关于初始化ActiveRecord的实体类对象

    ActiveRecord使用ORM的实体类对象之前要先初始化,官方网站上面有这么一句
    ActiveRecordStarter.Initialize( source, typeof(Blog) );
    如果每个类都要这样初始化才能用的话那就麻烦了。所以它建议你放在Global文件的Application_ Start方法里面。但是使用
    ActiveRecordStarter.Initialize( source, typeof(ActiveRecordBase));
    这句话的时候提示出错。
    You have accessed an ActiveRecord class that wasn't properly initialized. The only explanation is that the call to ActiveRecordStarter.Initialize() didn't include HelloCastle.DAL.PortalUser class 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

    异常详细信息: Castle.ActiveRecord.Framework.ActiveRecordException: You have accessed an ActiveRecord class that wasn't properly initialized. The only explanation is that the call to ActiveRecordStarter.Initialize() didn't include HelloCastle.DAL.PortalUser class

    源错误: 


    行 64: 
    行 65:         Public Overloads Shared Function FindAll() As PortalUser()
    行 66:             Return CType(ActiveRecordBase.FindAll(GetType(PortalUser)), PortalUser())
    行 67:         End Function
    行 68: 
     

    找了一些代码发现PortalUser也是从ActiveRecordBase继承的没错。后来发现Initialize方法有4种不同的版本。干脆把实体类的Modle的程序集HelloCastle.Model.dll都一起初始化了。
    ActiveRecordStarter.Initialize([Assembly].Load("HelloCastle.Model"), source)
    它放在Application_ Start方法里面。这下不用每次访问数据实体对象都要重复去初始化了.
  • 相关阅读:
    MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length
    递归枚举IHTMLDocument2的所有元素
    递归创建文件和文件夹
    通过ARP协议获取MAC地址
    监控文件(夹)的改变
    ATL和MFC的C++类和HWND的映射机制
    枚举当前环境中打开的所有IE
    封装字符串的Format操作
    python decimal和fractions模块
    解决Output Designer字体问题
  • 原文地址:https://www.cnblogs.com/Bruce_H21/p/403569.html
Copyright © 2011-2022 走看看