在Odata查询中使用$ expand内的$ filter

时间:2018-04-23 19:28:30

标签: asp.net-mvc asp.net-web-api odata

我正在尝试使用Odata查询(如

)在扩展实体中使用过滤器
   https://labstest.science.com/DEV/odata/ROOM_REQUEST?$expand=REQ_COLONYROOM($select=Name;$filter=Name eq 'RB05')

这部分有效。它为REQ_COLONYROOM带来所有ROOM_REQUEST和Null,其中Name不等于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
    }]}

虽然M1和M3的阵营与RB05不同,但它会通过odata调用返回Null

1 个答案:

答案 0 :(得分:1)

你有没有试过这样的事情:

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

我认为没有SELECT就足够了:

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