We have an oData rest api for querying data. ( written in c# )
This is a question about how $expand works when you are expanding a null reference.
I'm not sure what the expected behavior should be.
If we do an expand with a select, any null objects are simply returned as null.
e.g.
...&$expand=HighestAlarmType ($select = ObjectID, UniversalID)&...
Gives output:
{
...
"HighestAlarmType": null
},
But if we just do an expand without adding any columns in the select we get a "fake" expanded object with all null values showing up.
...&$expand=HighestAlarmType&...
Gives output:
"AssetNumber": "214",
"HighestAlarmType": {
"@odata.etag": "W/\"\"",
"Updates": null,
"ObjectID": null,
"DateAndTimeCreated": null,
"UniversalID": null,
"LastUpdatedOn": null,
"LastUpdatedBy": null,
"UserCreatedBy": null,
"AlarmTypeName": null,
"SeverityRanking": null,
"RangeColorToUseOnGauges": null,
"AlarmLevel": null,
"FailurePFIntervalOption": null,
"CalculateCompletionBasedonPF": null,
"LightColorToUseOnMobile": null,
"DarkColorToUseOnMobile": null,
"CollectorsNoteMandatory": null,
"DarkTextColorToUseOnMobile": null,
"LightTextColorToUseOnMobile": null,
"AcknowledgmentAllowFixed": null,
"AcknowledgmentAllowIncoAlarm": null,
"AcknowledgmentAllowIncoReading": null,
"AcknowledgmentAllowMonitoring": null,
"AcknowledgmentAllowWorkOrders": null,
"AcknowledgmentAllowWorkRequest": null,
"AcknowledgmentAllowWFromScratc": null,
"AcknowledgmentControlMethodsBy": null,
"PFIntervalAdjustment": null
}
Wondering if this is expected behavior or if there is something we are doing wrong.
I think oData expand should return just "null" if the reference is null.
An example is in the northwind query:
https://services.odata.org/V4/Northwind/Northwind.svc/Employees?$filter=FirstName eq 'Andrew'&$expand=Employee1&$top=5&$count=true
This yields:
"Employee1": null
I have also looked more deeply into our code and can see we have a bug in it and should be just returning null.