问题
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