By Magendran V


2018-10-17 13:53:25 8 Comments

I have some issues in Odata filter with nested property,

Controller:

[HTTPGet]
[EnableQuery]
public async Task<IQueryable<MyObj>> GetData()
{
    return await GetUserData();
}

Output from web app for the get url request,

GET https://sample.com/IB

[{
        "Id": "1",
        "FirstName": "Alex",
        "School": [
            {
                "SchoolId": "Sc1",
                "Roles": [
                    {
                        "Role": "ROOT",
                    }
                ],
                "Email": "[email protected]"
            }
        ]
    },    
    {
        "Id": "2",
        "FirstName": "Mage",
        "School": [
            {
                "SchoolId": "Sc2",
                "Roles": [
                    {
                        "Role": "Admin",
                    }
                ],
                "Email": "[email protected]"
            }
        ]
    }]

How to get the results of school, where SchoolId = "Sc2"

I have tried with below url,

GET https://sample.com/IB?$expand=School&$filter=School/SchoolId eq 'Sc2'

but I got the below error message,

{
    "Message": "The query specified in the URI is not valid. The parent value for a property access of a property 'SchoolId' is not a single value. Property access can only be applied to a single value."
}

Any thoughts?

1 comments

@Tony 2019-04-29 22:02:49

Late reply, but you need to go after the collection with the lambda any operator.

https://sample.com/IB?$expand=School&$filter=School/Any (c:c/SchoolId eq 'Sc2')

Related Questions

Sponsored Content

22 Answered Questions

11 Answered Questions

[SOLVED] Best practice to return errors in ASP.NET Web API

20 Answered Questions

[SOLVED] LINQ's Distinct() on a particular property

32 Answered Questions

[SOLVED] What is the difference between a field and a property?

  • 2008-11-17 08:41:38
  • Anonymous
  • 452481 View
  • 1127 Score
  • 32 Answer
  • Tags:   c# properties field

29 Answered Questions

[SOLVED] How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

16 Answered Questions

[SOLVED] Pass an array of integers to ASP.NET Web API?

19 Answered Questions

[SOLVED] How to Sort a List<T> by a property in the object

Sponsored Content