As Alexander said, without more info, this is more a guessing game than 
real help :-)
We'd need at least the query you issue (A dto with two list values? Are you 
sure that this conversion runs in SQL and not in C# code? Check with 
nhibernate profiler the SQL that is issued!).
Also query cache: are you really sure that it helps to improve your 
performance? Try to disable it and check if it works without it.
I am also not sure how well query cache and anonymous objects work together 
(ie if caching is even possible).
You might be better off writing your own little cache helper that caches 
results sets for a limited time.

best regards,
Peter

Am Freitag, 5. Februar 2016 17:09:11 UTC+1 schrieb Felipe Oriani:
>
> Hi PeSo, thanks for the answer
>
> We tried to execute a simple query without order and it fails. The select 
> only with Id fails too. 
>
> We were using NHibernate 3.3 and we updated to 4.0.4 and it started 
> working, great! But, it fails for another query with an AdoException.
>
> GenericADOException: The value "{ HoliDayCities = 
> System.Collections.Generic.List`1[System.Int64], HoliDayStates = 
> System.Collections.Generic.List`1[System.Int64], Date = 01/02/2015 00:00:00 
> }" is not 
> "<>f__AnonymousType1`3[System.Collections.Generic.List`1[System.Int64],System.Collections.Generic.List`1[System.Int64],System.DateTime]"
>  
> and cannot be used on this collection. Parameter name: value
>
> In hibernate.cfg.xml file we have defined the first level cache of the 
> session, but nothing for second level caching. 
>
> <property name="current_session_context_class">web</property>
> <property 
> name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
> <property 
> name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
> <property name="connection.connection_string">
> Our connection string is here for Oracle 10g
> </property>
> <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
> <property name="query.substitutions">true 1, false 0, yes 'Y', no 
> 'N'</property>
>
> <property name="adonet.batch_size">500</property>
> <property name="show_sql">true</property>
>
>
> *<property name="cache.use_query_cache">true</property>*
>
> Is there something you can suggest?
> We saw some problems reported in NHibernate Jira related with anonymous 
> objects, and we are not sure if it is the real problem. Works for the first 
> time, the second fails.
>
> Thank you.
>
>
>
>
>
>
>
> On Fri, Feb 5, 2016 at 6:39 AM, PeSo <peter....@gmail.com <javascript:>> 
> wrote:
>
>> Hm,
>> that's a strange one. Anonymous objects typically work. Also anonymous 
>> objects are not cached in in the session.
>> Maybe query caching? Is this enabled? 2nd level cache?
>>
>> Did you try to execute Select before Order?
>>
>> You are using the latest Nhibernate 4.0.4?
>>
>> best regards,
>> Peter
>>
>>
>> Am Mittwoch, 3. Februar 2016 13:48:00 UTC+1 schrieb Felipe Oriani:
>>
>>> Hello guys! 
>>>
>>> We have a web application which has some methods defined by user and 
>>> executed by Codedom (CSharpCodeProvider) between our code. Our customer has 
>>> programmers that can adpts business rules over the project and execute some 
>>> queries on the scope of execution. We have a simple query like below 
>>> execution on Codedom:
>>>
>>> var employeeTeam = Session.Query<EmployeeTeam>()
>>>                        .Where(x => x.StartEffective <= 
>>> competency.FinalDate && // competency.FinalDate is a DateTime
>>>                                    employeesIds.Contains(x.EmployeeId)) 
>>> // employeeIds is a List<long>
>>>                        .OrderByDescending(x => x.StartEffective)
>>>                        .Select(x => new
>>>                        {
>>>                            x.EmployeeId,
>>>                            x.StartEffective,
>>>                            x.Team
>>>                        }).ToList();
>>>
>>> It successfully runs once, but when executed in the second time (or 
>>> third, fourth and so son) it throws an invalid cast exception like:
>>>
>>> Fatal Error:System.InvalidCastException: Cannot convert type 
>>> 'System.Linq.EnumerableQuery`1[<>f__AnonymousType0`3[System.Int64,System.DateTime,Team]]'
>>>  
>>> to 
>>> 'System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`3[System.Int64,System.DateTime,Team]]'.
>>>  
>>> in NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression 
>>> expression)
>>> Rest of the stack trace supressed for bravety.
>>>
>>> The query is always executed in database before the error. It returns no 
>>> records, but it's ok. If we rebuild the solution and run again, the query 
>>> is executed in first time again, and then start throwing the exception each 
>>> other time I run it. Other queries runs everytime without any problems. We 
>>> have no idea of what causes the error.
>>>
>>> Its important to say that this code is running in an CSharpCodeProvider 
>>> environment, but we don't know if it can make a difference. We also tried 
>>> everything, for sample, removing Where(), OrderBy(), changing the Select() 
>>> return, etc... but no progress.
>>>
>>> We think the problem is with Anonnymous objects return because if we do 
>>> a DTO to return a result, it executes ok. If we just return a single value 
>>> using .Select(x => x.EmployeeId), it executes ok too. We do not want to 
>>> force the user defined a DTO for each custom query they can do. 
>>>
>>> We just realize that if I add the following property to the annon 
>>> object, the query works everytime:
>>>
>>> Rnd = (new Random().Next(1, 999))
>>>
>>> (it's a terrible solution but it worked)
>>>
>>> So, a cache issue maybe?
>>>
>>> Thank you.
>>>
>>> -- 
>>> ______________________________________
>>> Felipe B Oriani
>>> felipe...@gmail.com
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nhusers+u...@googlegroups.com <javascript:>.
>> To post to this group, send email to nhu...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/nhusers.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> ______________________________________
> Felipe B Oriani
> felipe...@gmail.com <javascript:>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To post to this group, send email to nhusers@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to