We will try to create a repository on github to share a scenario like this and we will back to post here.
On Thu, Feb 11, 2016 at 10:06 PM, Alexander Zaytsev <[email protected]> wrote: > I don't know. Trying to understand what's happening. > > > On Friday, 12 February 2016, Felipe Oriani <[email protected]> wrote: > >> No Alexander, the problem always happens. We have tested in a query with >> results and another one without results. The same problem happens. But is >> there any difference on it? >> >> Thank you. >> >> On Thu, Feb 11, 2016 at 10:22 AM, Alexander Zaytsev <[email protected]> >> wrote: >> >>> Felipe, so it happens only when query does not return any results, right? >>> >>> Best Regards, >>> Alexander >>> >>> On Fri, Feb 12, 2016 at 1:01 AM, Felipe Oriani <[email protected]> >>> wrote: >>> >>>> Hi PeSo and Alexander >>>> >>>> Just to remember you guys, the query executes fine in the scope of >>>> code, but if I pass the ISession to a dynamic class (executed by CodeDom), >>>> I got this exception. See the complete StackTrace. The temporary solution >>>> is to load the entire entity, avoiding using the Select method of >>>> IQueryable<T> and then using FirstOrDefault() or ToList(). The problem is >>>> that we do not want to load all the information and as PeSo said, we do not >>>> want to cache the entity in the first level. I think maybe the problem is >>>> with anonymous objects in CodeDom. >>>> >>>> em NHibernate.Impl.SessionImpl.List(IQueryExpression >>>> queryExpression, QueryParameters queryParameters, IList results) >>>> em NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression >>>> queryExpression, QueryParameters parameters) >>>> em NHibernate.Impl.AbstractQueryImpl2.List() >>>> em >>>> NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression >>>> nhLinqExpression, IQuery query, NhLinqExpression nhQuery) >>>> em NHibernate.Linq.DefaultQueryProvider.Execute(Expression >>>> expression) >>>> em NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression >>>> expression) >>>> em Remotion.Linq.QueryableBase`1.GetEnumerator() >>>> em System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) >>>> em System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) >>>> em Core.Customd4a5e8.InterventionWrapper.CustomExecuteDynamic(List`1 >>>> baseData, List`1 parameters) na >>>> c:\Users\GAtec\AppData\Local\Temp\pzwxqhvi.0.cs:linha 802 >>>> em Core.Customd4a5e8.InterventionWrapper.ExecuteDynamic(List`1 data, >>>> List`1 parameters, InterventionExecutionSetupInfo setup, List`1& debug) na >>>> c:\Users\username\AppData\Local\Temp\pzwxqhvi.0.cs:linha 242 >>>> em >>>> Core.Data.Intervention.InterventionMethod.Execute[T](InterventionExecutionParams >>>> execParams, List`1& resultLog, Boolean fromCallCmd) na >>>> C:\Projects\Core.Data\Intervention\InterventionMethod.cs:linha 721 >>>> >>>> I know it is a difficult scenario to simulate but that is it. >>>> Thanks you guys. >>>> >>>> >>>> >>>> >>>> >>>> On Mon, Feb 8, 2016 at 4:35 AM, PeSo <[email protected]> wrote: >>>> >>>>> 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 <[email protected]> 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 >>>>>>>> [email protected] >>>>>>>> >>>>>>> -- >>>>>>> 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 [email protected]. >>>>>>> To post to this group, send email to [email protected]. >>>>>>> Visit this group at https://groups.google.com/group/nhusers. >>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> ______________________________________ >>>>>> Felipe B Oriani >>>>>> [email protected] >>>>>> >>>>> -- >>>>> 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 [email protected]. >>>>> To post to this group, send email to [email protected]. >>>>> Visit this group at https://groups.google.com/group/nhusers. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> ______________________________________ >>>> Felipe B Oriani >>>> [email protected] >>>> >>>> -- >>>> 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 [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at https://groups.google.com/group/nhusers. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >>> 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 [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at https://groups.google.com/group/nhusers. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> ______________________________________ >> Felipe B Oriani >> [email protected] >> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/nhusers. >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/nhusers. > For more options, visit https://groups.google.com/d/optout. > -- ______________________________________ Felipe B Oriani [email protected] -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
