I am facing the following issue in a very

This statement works, I get the only employee "John"

var employee = session.QueryOver<Employee>().Where(x => x.Name ==
"John").List();

but this does not:

var employee = session.Query<Employee>().Where(x => x.Name ==
"John").ToList();

This is the error i get:
The type initializer for 'NHibernate.Linq.NhRelinqQueryParser' threw
an exception.

Stack Trace:
   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 Remotion.Data.Linq.QueryableBase`1.GetEnumerator() in :line 0
   at System.Collections.Generic.List`1..ctor(IEnumerable`1
collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at
DAL.Test.Repositories.EmployeeRepositoryFixture.CanGetEmployeeAsQueryable()


This is the inner exception:
Sequence contains more than one matching element
   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


The mapping is the following:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Test.Domain" namespace="Test.Domain" default-lazy="false">
  <class name="Employee" lazy="false">
    <id name="UniqueId" type="System.Guid">
      <column name="uid"  />
      <generator class="guid.comb" />
    </id>
    <property name="Name">
      <column name="name" />
    </property>
  </class>
</hibernate-mapping>


This is the hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</
property>
    <property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
    <property
name="connection.connection_string_name">EmployeesConnectionString</
property>
    <property
name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle</property>
    <property name="show_sql">true</property>
    <property name="generate_statistics">true</property>
    <property name="prepare_sql">true</property>
  </session-factory>
</hibernate-configuration>


I am sure there is a stupid error somewhere... someone has any clue?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com.
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to