zoukankan      html  css  js  c++  java
  • ActiveRecord Enabling lazy load 方案

    lazy load AR 官的方案是

                BeginRequest += new EventHandler(OnBeginRequest);
                EndRequest 
    += new EventHandler(OnEndRequest);

                
    // Initialization code omitted

            }

            
    protected void Application_End(object sender, EventArgs e)
            
    {

            }


            
    public void OnBeginRequest(object sender, EventArgs e)
            
    {
        
    //        HttpContext.Current.Items.Add("nh.sessionscope", new SessionScope());
            }


            
    public void OnEndRequest(object sender, EventArgs e)
            
    {
                
    //try
                
    //{
                
    //    SessionScope scope = HttpContext.Current.Items["nh.sessionscope"] as SessionScope;
                
    //    if (scope != null)
                
    //    {
                
    //        scope.Dispose();
                
    //    }
                
    //}
                
    //catch (Exception ex)
                
    //{
                
    //    HttpContext.Current.Trace.Warn("Error", "EndRequest: " + ex.Message, ex);
                
    //}
            }


    但我用这个办法,后来建了个PageBase.cs
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Castle.ActiveRecord;

    namespace Wz16.WebApp
    {
        
    public class PageBase : System.Web.UI.Page
        
    {
            
    protected SessionScope CurSessionScope ;
            
    protected override void OnInit(EventArgs e)
            
    {
                CurSessionScope 
    = new SessionScope();
                
    base.OnInit(e);
            }


            
    public override void Dispose()
            
    {
                
    try
                
    {
                    
    if (CurSessionScope != null)
                    
    {
                        CurSessionScope.Dispose();
                    }

                }

                
    catch (Exception ex)
                
    {
                    HttpContext.Current.Trace.Warn(
    "Error""EndRequest: " + ex.Message, ex);
                }

                
                
    base.Dispose();
            }

        }

    }

    继承自PageBase.cs的页面就都支持 AR 的 Lazy Load

    我用的 asp.net2.0 为什么官方的方案会不行,有知道的人请赐教。

  • 相关阅读:
    C# Redis实战(三)
    那些年我们一起追过的缓存写法(二)
    Linux Centos7 tomcat9安装配置,Centos Tomcat开机启动
    Mysql连接报错:Communications link failure
    WebLogic 12c静默安装
    Federated Learning with Matched Averaging
    xamarin调试显示详细的错误信息设置
    mongodb geometry地理空间数据库存储和索引
    GIS数据库设计
    mongodb脚本是使用什么语言编写的?mongodb怎么执行脚本?脚本怎么保存
  • 原文地址:https://www.cnblogs.com/shiningrise/p/887414.html
Copyright © 2011-2022 走看看