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

16 Answered Questions

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

21 Answered Questions

[SOLVED] What is the best way to give a C# auto-property an initial value?

20 Answered Questions

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

19 Answered Questions

[SOLVED] Does IMDB provide an API?

31 Answered Questions

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

  • 2008-11-17 08:41:38
  • Anonymous
  • 413888 View
  • 1028 Score
  • 31 Answer
  • Tags:   c# properties field

6 Answered Questions

[SOLVED] How to secure an ASP.NET Web API

0 Answered Questions

19 Answered Questions

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

29 Answered Questions

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

11 Answered Questions

[SOLVED] WCF vs ASP.NET Web API

Sponsored Content