Error using Linq for NHibernate

Error using Linq for NHibernate

Postby DarkCamper » Wed 18 Mar 2015 17:43

Hi. I'm using dotConnect for PostgreSQL with NHibernate as explained in this post: http://forums.devart.com/viewtopic.php?f=3&t=28844.

I can open a session and execute a HQL query succesfully, but the same query using Linq throws this exception.

Code: Select all
"NHibernate.Exceptions.GenericADOException: could not execute query
[ select tenant0_.id as id0_, tenant0_.nombre as nombre0_, tenant0_.tenant_base as tenant3_0_ from core.tenant tenant0_ where tenant0_.id>:p0 ]
  Name:p1 - Value:1
[SQL: select tenant0_.id as id0_, tenant0_.nombre as nombre0_, tenant0_.tenant_base as tenant3_0_ from core.tenant tenant0_ where tenant0_.id>:p0] ---> Devart.Data.PostgreSql.PgSqlException: Parameter 'p0' is missing
   en Devart.Data.PostgreSql.PgSqlCommand.a(String A_0, Boolean A_1)
   en Devart.Data.PostgreSql.PgSqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
   en Devart.Common.DbCommandBase.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
   en Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
   en Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
   en System.D
ata.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
   en NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
   en NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
   en NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   en NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
   en NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
   --- Fin del seguimiento de la pila de la excepción interna ---
   en NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
   en NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
   en NHibernate.Loader.Loader.List(ISessionImplemen
tor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
   en NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
   en NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
   en NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
   en NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
   en NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
   en NHibernate.Impl.ExpressionQueryImpl.List()
   en NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
   en NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
   en NHibernate.Linq.DefaultQueryProvider.Execute[TResult](
Expression expression)
   en Remotion.Linq.QueryableBase`1.GetEnumerator()
   en System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   en System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   en ErrorDevartPotgreSQL.Form1.Form1_Load(Object sender, EventArgs e) en o:\\Pruebas\\ErrorDevartPotgreSQL\\ErrorDevartPotgreSQL\\Form1.cs:línea 56"


And this is the code i've tested
Code: Select all
Configuration cfg = new Configuration().AddAssembly(typeof(Program).Assembly);
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();

//This works
var query = session.CreateQuery("from Tenant where Id > 1");
var res = query.List();

//This throws the exception
var query2 = session.Query<ErrorDevartPotgreSQL.Tenant>().Where(x => x.Id > 1);
var res2 = query2.ToList();

I've tried with NH versions 3.3.4 and 4.0.1 to the same effect. DotConnect version is 7.3.352.0 and PostgreSql is 9.4.

Do you have any idea about what could be wrong?

Thanks!
DarkCamper
 
Posts: 9
Joined: Wed 18 Mar 2015 17:31

Re: Error using Linq for NHibernate

Postby MariiaI » Thu 19 Mar 2015 11:45

We couldn't reproduce this error in our environment. Please send us a small test project with the necessary DDL/DML scripts, with which this issue could be reproduced. This will significantly speed up the process of determining the cause of this issue.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Error using Linq for NHibernate

Postby DarkCamper » Thu 26 Mar 2015 09:38

Hi, have you been able to replicate the problem using the small project I sent you?

If you need more information or something just ask for it, I'll gladly help you.

Thanks.
DarkCamper
 
Posts: 9
Joined: Wed 18 Mar 2015 17:31

Re: Error using Linq for NHibernate

Postby MariiaI » Thu 26 Mar 2015 13:03

Sorry for the delay. Your letter was blocked by our mail filter for some reason. We have reproduced the issue with your sample project. This behaviour is related to NHibernate, not dotConnect for PostgreSQL. To avoid the error, please open the DevartDriver.cs file and replace this code:
Code: Select all
public override string NamedPrefix
        {
            get { return ":"; }
        }


with this
Code: Select all
public override string NamedPrefix
        {
            get { return "@"; }
        }

Please tell us if this helps.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Error using Linq for NHibernate

Postby DarkCamper » Thu 26 Mar 2015 13:17

It works! Thanks a lot for your help
DarkCamper
 
Posts: 9
Joined: Wed 18 Mar 2015 17:31


Return to dotConnect for PostgreSQL