This repository has been archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Issue with Any in OData $filter clause. #23
Comments
Hi!
I wouldn't recommend doing that. It will totally break the logic of this method. The problem is that method doesn't handle correctly the case when Instead, change the method as follows: public static System.Type TryGetCollectionItemType(System.Type collectionType)
{
if (collectionType == null)
return null;
System.Type enumerableType;
if (collectionType.IsGenericType && collectionType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
enumerableType = collectionType;
else
enumerableType = collectionType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable<>));
if (enumerableType == null)
return null;
return enumerableType.GetGenericArguments().Single();
} It will first check whether the value of Assert.AreEqual(typeof(int), OData.TypeUtil.TryGetCollectionItemType(typeof(IEnumerable<int>))); |
pvginkel
added a commit
that referenced
this issue
Sep 27, 2015
The code that recognizes whether a property is a collection did not check the actual type of the collection for being an enumerable interface. Bug: #23
Sorry for the late reply. I'll push a new version to NuGet in a moment with this fix. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
Thanks for this great library. I'd love to see it grow.
I've got an issue with a queries such as:
people?$filter=EmploymentsList/any(o: o/Salary eq 2.5)
Where EmploymentsList is a property on People and is defined as:
I receive the following error:
"Cannot get collection item type"
Unfortunately, I cannot change the definition of .EmploymentsList and so would like to change nHibernate.odata instead. I can see the issue lies in NHibernate.OData.TypeUtil.TryGetCollectionItemType at this line:
And enumerableType is returned as null.
Unfortunately, my knowledge of reflection isn't brilliant and would need some pointers but would adding a line such as:
be acceptable? If it is, I'll get on and write a unit test and send a pull request.
The text was updated successfully, but these errors were encountered: