因为前几天我觉得很冒险,所以我决定用ActiveRecord 3 RC 1编译NHibernate 3.2,看看会发生什么。
除了我修复的中断更改之外,我还遇到了一个关于SessionScopes和Linq查询的非常奇怪的行为。
通常,在使用Linq查询时,我不必使用会话范围,但是在用ActiveRecord 3 RC 1编译NHibernate 3.2之后,我得到了以下错误:
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似乎这个错误是从这里来的:
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
发布于 2011-11-22 10:51:08
我在Queryable函数上也遇到了麻烦。虽然我没有会话范围问题,但我无法将更新保存到IQueryable检索的对象。新的会议似乎从未在活动范围内登记过。我还更改了范围检索,因此这可能对您也有帮助:
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>();
}
}https://stackoverflow.com/questions/7174251
复制相似问题