简体   繁体   English

通过Web API OData中的嵌套属性过滤

[英]Filter by nested property in web api odata

I have some issues in Odata filter with nested property, 我在具有嵌套属性的Odata过滤器中遇到一些问题,

Controller: 控制器:

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

Output from web app for the get url request, 从Web应用输出的获取url请求,

GET https://sample.com/IB

[{
        "Id": "1",
        "FirstName": "Alex",
        "School": [
            {
                "SchoolId": "Sc1",
                "Roles": [
                    {
                        "Role": "ROOT",
                    }
                ],
                "Email": "abc@xyz.com"
            }
        ]
    },    
    {
        "Id": "2",
        "FirstName": "Mage",
        "School": [
            {
                "SchoolId": "Sc2",
                "Roles": [
                    {
                        "Role": "Admin",
                    }
                ],
                "Email": "abc@xyz.com"
            }
        ]
    }]

How to get the results of school, where SchoolId = "Sc2" 如何获得学校的成绩,其中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? 有什么想法吗?

回复较晚,但是您需要使用lambda any运算符来进行收集。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM