Uh oh!
There was an error while loading. Please reload this page.
Create webapi action filter for filtering IQueryables - #16
Conversation
8394ebe to
8fc80dbCompareSphtKr
commented
Jan 21, 2015
The last bullet here bothers me, but there's not currently a solution in the spec for explicitly filtering on null as a value. So, I've opened an issue on it, we'll see if it gets any attention. The main use case that strikes me as a problem is querying for an empty string value...this being the implementation, that's not possible. If we go the other way for strings, it's not possible to query for nulls. Tricky.
Yeah, it's a pity this will be a tougher nut to crack, which I hadn't really considered...and darn it the spec's examples are exactly that. We'll merge as is, but we're going to want this too eventually. |
There was a problem hiding this comment.
This looks like it has two typos that cause the test to fail, should this be:
var returnedArray = GetArray<Dummy>("http://api.example.com/dummies?stringField=String value 2&enumField=3");
?
There was a problem hiding this comment.
Yeah, you're right. I'll fix that.
SphtKr
commented
Jan 21, 2015
Also, is there a reason you put this in JSONAPI.EntityFramework? I don't see any EF specific code, and in theory any ApiController's Get method could return an IQueryable that should work with this code, I think...am I missing something in the generics gymnastics that assumes an EF-backed IQueryable? |
SphtKr
commented
Jan 21, 2015
One last question: any objection to naming it I'm also thinking ahead to sorting, which I'm guessing will become another ActionFilter probably named |
SphtKr
commented
Jan 21, 2015
Or, Okay I'm done. |
csantero
commented
Jan 21, 2015
You're right, I was being stupid. For some reason I thought that all the extension methods like Where are defined by EF. But that doesn't make any sense. I just looked them up and of course they're in System.Linq. I'll move the filter to JSONAPI. |
csantero
commented
Jan 21, 2015
I have no objection to renaming it to reflect its role in filtering. The words ActionFilter might be redundant too. FilteringAttribute might be too generic. JsonApiFilteringAttribute? QueryFilteringAttribute? FilteringQueryableAttribute? Naming stuff is hard... |
csantero
commented
Jan 21, 2015
Oh, I guess I should have read this before I commented. Yeah, this is better. |
8fc80db to
41a2b79Compare41a2b79 to
5de86dcComparecsantero
commented
Jan 21, 2015
@SphtKr New diff is up. |
Create webapi action filter for filtering IQueryables
SphtKr
commented
Jan 21, 2015
Supports #14, but let's see if we can get object IDs to work before we close that one. |
This adds a new action filter called JsonApiQueryableActionFilterAttribute that can be inserted into the WebAPI pipeline. It detects if the object content is an IQueryable<>. If it is, the filter performs exact-match filtering according to the json-api spec.
Filtering is supported for the following types:
as well as their nullable counterparts. There is not yet support for linked IDs.
A few notes on the behavior:
GET /people?firstName=John&lastName=Doewill yield all people whose first name is John AND last name is Doe.GET /people?firstName=John&firstName=Bill, the behavior is undefined.