Skip to content
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

Filters on sub-properties / model binding a filter Predicate #41

Open
mcintyre321 opened this issue Aug 28, 2014 · 3 comments
Open

Filters on sub-properties / model binding a filter Predicate #41

mcintyre321 opened this issue Aug 28, 2014 · 3 comments
Labels

Comments

@mcintyre321
Copy link

Hi Pete!

I've got a requirement to add take/skip/filter on a sub-property for an resource like this:

{
  "Owner": "123",
   //  ... more properties ...
  "Activities": [
    {
      "ActivityType": "sample string 1",
       //  ... more properties ...
    },
    {
      "ActivityType": "sample string 2",
       //  ... more properties ...
    }
  ],
  "TotalCount": 2
}

Rather than add yet another parameter to the controller, is there any way to use L2QS to model bind an a filter for the activities collection? e.g.

    public MyResponse(int ownerId, Func<Activity, bool> activitiesFilter) {
        var owner = _owners.Single(o => o.OwnerId);
        owner.Activities.RemoveAll(activitiesFilter);
        return owner;
    }

It would also be handy to be able to model bind Expression<Func<Activity, bool>> so I could pass it into a Queryable.

Or maybe is this already possible by doing a projection and mapping back to the original model type?

@mcintyre321 mcintyre321 changed the title Filters on sub-properties \ model binding a filter Predicate Filters on sub-properties / model binding a filter Predicate Aug 28, 2014
@beyond-code-github
Copy link
Owner

Have you tried using the collection operators? As far as I'm aware they should work in this situation eg (from the website):

Collection Operators
any /Categories?$filter=Products/any(p: p/Rating lt 4)
all /Categories?$filter=Products/all(p: p/Rating ge 7)

@beyond-code-github
Copy link
Owner

Oh hang on a moment, do you mean filtering just the sub-collection and leaving the rest intact?

@mcintyre321
Copy link
Author

Yes, that's the requirement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants