Search code examples
sqlwcfodata

OData Related Field Select Syntax


Just wondering what the proper syntax is to add a related field to a select statement. Example Employees all have a department which is set in the departmentID field in the Employee table. What is the OData select syntax if i want to pull back all employees but only want to show their FirstName and DepartmentName. I was thinking it would be something like http://example.com/odata.svc/Employees?$select=FirstName,+Department.DepartmentName


Solution

  • The syntax for that is: http://mywebsite.com/odata.svc/Employees?$select=FirstName,Department/DepartmentName&$expand=Department

    A related (working) example from Stack Overflow's OData API would be: http://odata.stackexchange.com/stackoverflow/atom/Users?$select=DisplayName,Badges/Name&$expand=Badges