首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActiveRecord 3 RC 1与NHibernate 3.2一起导致意外异常

ActiveRecord 3 RC 1与NHibernate 3.2一起导致意外异常
EN

Stack Overflow用户
提问于 2011-08-24 10:51:41
回答 1查看 422关注 0票数 1

因为前几天我觉得很冒险,所以我决定用ActiveRecord 3 RC 1编译NHibernate 3.2,看看会发生什么。

除了我修复的中断更改之外,我还遇到了一个关于SessionScopes和Linq查询的非常奇怪的行为。

通常,在使用Linq查询时,我不必使用会话范围,但是在用ActiveRecord 3 RC 1编译NHibernate 3.2之后,我得到了以下错误:

代码语言:javascript
复制
Could not found a registered Scope. Linq queries needs a underlying a scope to be functional.
Stack Trace:    at Castle.ActiveRecord.Framework.ActiveRecordLinqBase`1.get_Queryable()
   at Castle.ActiveRecord.Framework.ActiveRecordLinq.AsQueryable[T]()
   at Danel.Nursing.Scheduling.Actions.DataServices.BranchDataService.GetBranches() in D:\Work\Default\Scheduling\Danel.Nursing.Scheduling.Actions\DataServices\BranchDataService.cs:line 21
   at Danel.Nursing.Scheduling.Controllers.SmallHoursAmountController.<>c__DisplayClassb.<SetBranches>b__a() in D:\Work\Default\Scheduling\Danel.Nursing.Scheduling\Controllers\SmallHoursAmountController.cs:line 275
   at Danel.Nursing.Scheduling.Viewlets.WaitForAction.Worker_DoWork(Object sender
DoWorkEventArgs e) in D:\Work\Default\Scheduling\Danel.Nursing.Scheduling\Viewlets\WaitForAction.cs:line 40

似乎这个错误是从这里来的:

代码语言:javascript
复制
public class ActiveRecordLinqBase<T> : ActiveRecordBase<T>
{
        public static IOrderedQueryable<T> Queryable
        {
            get
            {
                var activeScope = holder.ThreadScopeInfo.GetRegisteredScope(); // The registered scope is null...

                if (activeScope == null)
                    throw new ActiveRecordException("Could not found a registered Scope. Linq queries needs a underlying a scope to be functional.");

                var key = holder.GetSessionFactory(typeof(T));

                var session = activeScope.IsKeyKnown(key) ? activeScope.GetSession(key) : SessionFactoryHolder.OpenSessionWithScope(activeScope, key);

                return session.AsQueryable<T>();
            }
        }
    }

现在我必须打开一个新的SessionScope

EN

回答 1

Stack Overflow用户

发布于 2011-11-22 10:51:08

我在Queryable函数上也遇到了麻烦。虽然我没有会话范围问题,但我无法将更新保存到IQueryable检索的对象。新的会议似乎从未在活动范围内登记过。我还更改了范围检索,因此这可能对您也有帮助:

代码语言:javascript
复制
   public new IOrderedQueryable<T> Queryable
    {
        get
        {
            ISessionFactory key = ActiveRecordMediator<T>.GetSessionFactoryHolder().GetSessionFactory(typeof(T));
            ISessionScope activeScope = SessionScope.Current;

            if (activeScope == null)
                throw new ActiveRecordException("Could not found a registered Scope. Linq queries needs a underlying a scope to be functional.");

            var session = activeScope.IsKeyKnown(key) ? activeScope.GetSession(key) : OpenSessionWithScope(activeScope, key);

            if (!activeScope.IsKeyKnown(key))
            {
                activeScope.RegisterSession(key,session);
            }
            return session.AsQueryable<T>();
        }
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7174251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档