简体   繁体   English

NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser异常“序列包含多个匹配元素”

[英]NHibernate 3.1 NHibernate.Linq.NhRelinqQueryParser exception “Sequence contains more than one matching element”

I'm using Nhibernate 3.1 / FluentNhibernate 1.2 我正在使用Nhibernate 3.1 / FluentNhibernate 1.2

When I work in release mode with CTRL + F5, I don't get any exception. 当我使用CTRL + F5在发布模式下工作时,我没有任何异常。 But in debug mode with F5 following exception occurs: 但在调试模式下,F5发生以下异常:

A console application, for this code : 控制台应用程序,用于此代码:

_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: 

in my team we have the same error using the same versions of nHibernate and fluentnhibernate, anyway that error appears only on one machine (out of 8). 在我的团队中,我们使用相同版本的nHibernate和fluentnhibernate也有同样的错误,无论如何,错误只出现在一台机器上(8个中)。 It seems a problem inherent the debug of visual studio, the same project run fine if started outside visual studio or if the debug process is done through attaching the process from the Debug menu. 这似乎是visual studio的调试固有的问题,如果在visual studio外部启动,或者如果通过从Debug菜单附加进程完成调试过程,则同样的项目运行正常。 I'll investigate on this as soon as possible, but at this moment the debug from this pc is done indirectly as depicted above. 我会尽快对此进行调查,但此时此PC的调试是间接完成的,如上所述。 Also, this request http://www.mail-archive.com/nhusers@googlegroups.com/msg25959.html seems interesting. 此外,此请求http://www.mail-archive.com/nhusers@googlegroups.com/msg25959.html似乎很有趣。

One of the team member had this issue only when he debugged with VSDEV. 其中一名团队成员只有在使用VSDEV进行调试时才遇到此问题。

After we turning off IntelliTrace fixed this issue. 我们关闭IntelliTrace后解决了这个问题。

I had this same issue, it happens only when I try to use the NHibernate.Linq library. 我遇到了同样的问题,只有当我尝试使用NHibernate.Linq库时才会发生这种情况。 (I'm using NHibernate 3.1, and NHibernate.Linq 1.0). (我正在使用NHibernate 3.1和NHibernate.Linq 1.0)。 I didn't want to lose the ability to debug my application in Visual Studio, so I converted the NHibernate.Linq calls to the NHibernate QueryOver API instead, which is similar to Linq but doesn't actually use it. 我不想失去在Visual Studio中调试我的应用程序的能力,所以我将NHibernate.Linq调用转换为NHibernate QueryOver API,这类似于Linq但实际上并没有使用它。

So for your code example, you could change this: 因此,对于您的代码示例,您可以更改此:

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

To use QueryOver instead: 要使用QueryOver:

_Session.QueryOver<Foo>().Where(x => x.Bar == "bar").List().FirstOrDefault();

If you do that, you should be able to debug in Visual Studio now, without getting the same exception (at least I did). 如果你这样做,你应该能够立即在Visual Studio中进行调试,而不会得到相同的异常(至少我做过)。

I wrestled with this issue too for a couple of days trying to figure out why in the world I was the only one in my team getting that error. 我也在这个问题上进行了几天的努力,试图弄清楚为什么在这个世界上我是团队中唯一一个犯这个错误的人。

I am not exactly sure of all the paths that I took, however, in my case it turned out to be a privileges error, even though my domain login was an admin on the local box, and I was running everything on full trust, and UAC was off. 我不完全确定我采取的所有路径,但是,在我的情况下,它被证明是一个权限错误,即使我的域名登录是本地方框上的管理员,并且我在完全信任的情况下运行所有​​内容,并且UAC关闭了。

The trick that did it for me was to completely delete my windows profile and recreate it again. 为我做的诀窍是完全删除我的Windows配置文件并重新创建它。 I have no idea what in the profile was causing the issue, but it worked for me. 我不知道配置文件中是什么导致了这个问题,但它对我有用。

Hope this helps 希望这可以帮助

-Diego -Diego

Check your intellitrace settings! 检查你的intellitrace设置!

For me, it works when IntelliTrace events only is selected. 对我来说,仅在选择IntelliTrace事件时才有效。 When I have IntelliTrace events and call information selected, I get the nhibernate bug. 当我选择IntelliTrace事件和调用信息时,我得到了nhibernate错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Linq InvalidOperationException:序列包含多个匹配元素 - Linq InvalidOperationException: Sequence contains more than one matching element SingleOrDefault()引发异常序列包含多个匹配元素 - SingleOrDefault() Throw exception Sequence contains more than one matching element Sequence包含多个匹配元素 - Sequence contains more than one matching element LINQ.FromSQL 错误 InvalidOperationException: 序列包含多个匹配元素 - LINQ .FromSQL error InvalidOperationException: Sequence contains more than one matching element Include()ThenInclude()在Table Per Hierarchy策略中抛出“Sequence包含多个匹配元素”异常 - Include() ThenInclude() throws “Sequence contains more than one matching element” exception in Table Per Hierarchy strategy FirstOrDefault抛出'Sequence包含多个匹配元素' - FirstOrDefault throws 'Sequence contains more than one matching element' 实体框架 | 序列包含多个匹配元素 - Entity Framework | Sequence contains more than one matching element LINQ to SQL错误? 序列包含多个元素 - LINQ to SQL bug? Sequence contains more than one element Sequence包含多个元素异常,但在数据库中只有一个 - Sequence contains more than one element exception but in the database is just one Linq to NHibernate:序列不包含任何元素 - Linq to NHibernate: Sequence Contains no Elements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM