-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid cast exception when using inlinecount #30
Comments
This is my current nuget package: <package id="LinqToQuerystring" version="0.7.0.7" targetFramework="net45" /> |
Hi @mbonig, In this situation I think you need to pass a couple of type parameters to the LinqToQuerystring extension method to help it along:
The reason for this is that it has to return a structure containing the count and the records, and the dictionary was the easiest way to do this. I'm looking at ways of making this slightly nicer though. Let me know if this helps |
I'm a bit confused then. I understand it returning that type, but what is the expected behavior if the string being passed in does not contain inlinecount? Should I always expect a dictionary regardless? |
Because the common use case for Linq to Querystring is that the output is immediately serialized to json or xml for transfer down the wire, you can usually rely on the serialiser to take the ouput and deal with it regardless of the actual type. You can also use the non-generic overload...
...which returns an object so you can deal with this scenario or even check to see if you've got a dictionary or a queryable back if you need to. |
Thanks! I'm not doing the usual case here, as I need to apply this query pretty low in code. I'm going to do everything around object and handle the type, because I want the inline count returned in a different manner. Thanks! |
Trying to use inline count:
var asQueryable = new List
{
"one",
"two",
"three"
}.AsQueryable();
throws a:
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.Dictionary
2[System.String,System.Object]' to type 'System.Linq.IQueryable
1[System.String]'.Expected to get results with "3" and "two".
if I remove the inlinecount piece no error is thrown.
The text was updated successfully, but these errors were encountered: