WCF tutorial | OData Expression
This section lets understand following set of operation in resource by applying query in url
- To return the resource in different format
- Filter the records
- Read only the required fields
- Ordering the records
All the query URL mentions below are applied on top of Service create in above article. Refer "Create OData Service" section.
Comments: Return all the resource available in "People" property in AtomPub(feeds) format (default)
Comments: Return the resource in JSON format
Comments: Return only the "Person" with business ID (primary key) = "5"
Comments: Returns only the selected fields from select option
Comments: This url returns only top 3 by skipping the first 20 records and on "allpages" means that query is applied on all page
Consider scenario when return values of the query is very large amount of data. Does system return all value?
No, system will return only the set of records which is mention in the service setting (Max number of records). System automatically applies the Pagination to give only set of records. Resource for the next set of records are access by URL provide by system at end of First set of records
- $top â€“ specifies how many results should be returned in the current response
- $skip â€“ specifies how many records that satisfy the current criterion should be skipped
- $skiptoken â€“ specifies that all results from the start to the some id should be skipped
- $inlinecount â€“ if it is set to allpages requires that total number of records should be returned.
Comments: return the records in ascending or descending order
- Always create the service with Interface->Implementation format, mention the contract in Interface.
- Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
- Change the instance mode to per call as default.
- Always catch exception using try/catch block and throw exception using FaultException < T >.
- Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.