草庐IT

c# - NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser 异常 "Sequence contains more than one matching element"

coder 2024-05-28 原文

我正在使用 Nhibernate 3.1/FluentNhibernate 1.2

当我使用 CTRL + F5 在 Release模式下工作时,我没有遇到任何异常。 但是在使用 F5 的 Debug模式下会发生以下异常:

此代码的控制台应用程序:

_Session.Query<Foo> ().Where (x=>x.Bar == "bar").FirstOrDefault()

异常(exception):

System.TypeInitializationException was unhandled
  Message=The type initializer for 'NHibernate.Linq.NhRelinqQueryParser' threw an exception.
  Source=NHibernate
  TypeName=NHibernate.Linq.NhRelinqQueryParser
  StackTrace:
       at NHibernate.Linq.NhRelinqQueryParser.Parse(Expression expression)
       at NHibernate.Linq.NhLinqExpression.Translate(ISessionFactoryImplementor sessionFactory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhLinqExpression.cs:line 65
       at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 27
       at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 34
       at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 23
       at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 21
       at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 88
       at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 312
       at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 268
       at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 43
       at NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 26
       at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 103
       at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
       at x.Persistence.NH.NHibernateUnitOfWork.<>c__DisplayClass11`1.<FindOne>b__10() in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 71
       at x.Persistence.NH.NHibernateUnitOfWork.Transactional[TResult](Func`1 func) in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 88
       at x.Persistence.NH.NHibernateUnitOfWork.FindOne[T](Expression`1 predicate) in D:\x\x\x.Persistence.NH\NHibernateUnitOfWork.cs:line 71
       at Sample.Sam.Start() in D:\x\x\Sample\Sam.cs:line 28
       at Sample.Sam.Main() in D:\x\x\Sample\Sam.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
       Message=Sequence contains more than one matching element
       Source=System.Core
       StackTrace:
            at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
            at Remotion.Data.Linq.Parsing.ExpressionTreeVisitors.Transformation.ExpressionTransformerRegistry.CreateDefault() in :line 0
            at NHibernate.Linq.NhRelinqQueryParser..cctor() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhRelinqQueryParser.cs:line 26
       InnerException: 

最佳答案

在我的团队中,我们使用相同版本的 nHibernate 和 fluentnhibernate 时遇到相同的错误,无论如何该错误只出现在一台机器上(8 台机器中)。这似乎是 visual studio 调试固有的问题,如果在 visual studio 外部启动,或者如果调试过程是通过从“调试”菜单附加过程来完成的,则同一个项目运行良好。我会尽快对此进行调查,但目前这台电脑的调试是间接完成的,如上所述。另外,这个请求http://www.mail-archive.com/nhusers@googlegroups.com/msg25959.html似乎很有趣。

关于c# - NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser 异常 "Sequence contains more than one matching element",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5993893/

有关c# - NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser 异常 "Sequence contains more than one matching element"的更多相关文章

随机推荐