示例#1
0
        public IHttpActionResult GetCount()
        {
            DataTable Source = TestData.GetData();

            ODataTableFilter.Result Output = Source.ApplyODataQuery(this.Request);

            Output.RequestedOutputFormat = ODataTableFilter.OutputFormat.DataWithMetaDataAndCount;

            String AddressBase = $"{this.Request.RequestUri.Scheme}://{this.Request.RequestUri.Host}:{this.Request.RequestUri.Port}";

            //Path to this endpoint - used for generating Next links when returning paged data
            String EndpointAddress = $"{AddressBase}/api/Test";
            //Path to the metadata for this entity's context, including reference to this specific entity set
            String MetaDataAddress = $"{AddressBase}/api/$metadata#Test";

            ODataReturn ReturnData = new ODataReturn(Output, EndpointAddress, MetaDataAddress);

            return(ReturnData.GenerateCountResponseMessage(this));
        }
示例#2
0
        public IHttpActionResult Get()
        {
            DataTable Source = TestData.GetData();

            ODataTableFilter.Result Output = Source.ApplyODataQuery(this.Request);

            String AddressBase = $"{this.Request.RequestUri.Scheme}://{this.Request.RequestUri.Host}:{this.Request.RequestUri.Port}";

            //Path to this endpoint - used for generating Next links when returning paged data
            String EndpointAddress = $"{AddressBase}/api/Test";
            //Path to the metadata for this entity's context, including reference to this specific entity set
            String MetaDataAddress = $"{AddressBase}/api/$metadata#Test";

            ODataReturn ReturnData = new ODataReturn(Output, EndpointAddress, MetaDataAddress);

            //Workaround method to convert data columns that are not based on Edm mappable types - currently only known one is DateTime, which is mapped to DateTimeOffset
            ReturnData.PatchUpValueTypes();

            //Returns a specialised OkNegotiatedContentResult that ensures JSON serialisation, and included the OData-Version header
            // http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31358862
            return(ReturnData.GenerateResponseMessage(this));
        }