using the $filter inside the $expand in the Odata query

梦想的初衷 提交于 2020-06-16 07:22:05

问题


I am trying to use the filter in the expanded entity using the Odata query like

   https://labstest.science.com/DEV/odata/ROOM_REQUEST?$expand=REQ_COLONYROOM($select=Name;$filter=Name eq 'RB05')

This works partially. It brings all the ROOM_REQUEST with Null for the REQ_COLONYROOM where Name is not equal to RB05

{
"@odata.context": "https://labstest.science.com/DEV/odata/$metadata#ROOM_REQUEST(REQ_COLONYROOM(Name))",
"value": [
    {
        "Id": 18399308,
        "Name": "M1",
        "Barcode": "M1",
        "REQ_COLONYROOM": null
    },
    {
        "Id": 18403071,
        "Name": "M2",
        "Barcode": "M2",
        "REQ_COLONYROOM": {
            "@odata.id": "https://labstest.science.com/odata/COLONY_ROOM('MC19')",
            "Name": "RB05"
        }
    },
    {
        "Id": 18403109,
        "Name": "M3",
        "Barcode": "M3",
        "REQ_COLONYROOM": null
    }]}

Though M1 and M3 has different Colony than RB05 it returns Null with the odata call


回答1:


Did you try something like this:

 https://labstest.science.com/DEV/odata/ROOM_REQUEST?$expand=REQ_COLONYROOM&$select=REQ_COLONYROOM/Name&$filter=REQ_COLONYROOM/Name eq 'RB05'

I think it would be enough not having SELECT:

 https://labstest.science.com/DEV/odata/ROOM_REQUEST?$expand=REQ_COLONYROOM&$filter=REQ_COLONYROOM/Name eq 'RB05'


来源:https://stackoverflow.com/questions/49988592/using-the-filter-inside-the-expand-in-the-odata-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!