NHibernate 5 - IQueryable<T> on collections causes crashes when using AsQueryable #3323
Replies: 2 comments
-
Would calling Without a test case illustrating the issue, it is hard to understand if that may be suitable. Of course, this solution comes with an overhead: the collection, if not already loaded, will be loaded, and then, already loaded or not, duplicated.
|
Beta Was this translation helpful? Give feedback.
-
Another solution may be to use a custom class CustomPersistentGenericSet<T> : PersistentGenericSet<T>, IQueryable<T>
{
[NonSerialized]
IQueryable<T> _queryable;
Expression IQueryable.Expression => InnerQueryable.Expression;
System.Type IQueryable.ElementType => InnerQueryable.ElementType;
IQueryProvider IQueryable.Provider => InnerQueryable.Provider;
IQueryable<T> InnerQueryable => _queryable ?? (_queryable = new EnumerableQuery<T>(this));
} |
Beta Was this translation helpful? Give feedback.
-
NHibernate version: 5.4.2
.net Framework version: 4.8
In previous versions persistent collections did not implement IQueryable and it was possible to use AsQueryable to work with System.Linq.Dynamic using the result.
With NHibernate 5 AsQueryable now creates a linq query provider due to the implementation of IQueryable.
In my case creating the query provider throws a null reference exception and basically breaks everytime when working with System.Linq.Dynamic and persistent collections.
Is there any way to work around this other than not using AsQueryable on persistent collections, I basically just need a IQueryable for an IEnumerable (the actually type is only known at runtime) which worked just fine before?
I noticed there is a way to add a custom query provider using the LinqQueryProviderType but I am not sure if this is really the way to go.
Beta Was this translation helpful? Give feedback.
All reactions