ODataContext

The ODataContent is an object that provides access to an entire OData service.

Included in: dx.mobile.js, dx.web.js, dx.viz.js, dx.viz-web.js, dx.all.js
Export: default
Type:

Object

This object creates several ODataStore instances. Each instance accesses an individual entity collection.

jQuery
JavaScript
var context = new DevExpress.data.ODataContext({
    url: "http://www.example.com/Northwind.svc",
    entities: {
        Categories: {
            key: "CategoryID",
            keyType: "Int32"
        },
        // An entity collection alias
        Clients: {
            name: "Customers",
            key: "CustomerID",
            keyType: "String"
        },
        Products: {
            // A composite key
            key: ["ProductID", "ProductCode"],
            keyType: {
                ProductID: "Guid",
                ProductCode: "Int32" 
            }
        }
    }
});
Angular
TypeScript
import ODataContext from "devextreme/data/odata/context";
// ...
export class AppComponent {
    context: ODataContext;
    constructor () {
        this.context = new ODataContext({
            url: "http://www.example.com/Northwind.svc",
            entities: {
                Categories: {
                    key: "CategoryID",
                    keyType: "Int32"
                },
                // An entity collection alias
                Clients: {
                    name: "Customers",
                    key: "CustomerID",
                    keyType: "String"
                },
                Products: {
                    // A composite key
                    key: ["ProductID", "ProductCode"],
                    keyType: {
                        ProductID: "Guid",
                        ProductCode: "Int32" 
                    }
                }
            }
        });
    }
}
AngularJS
JavaScript
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.context = new DevExpress.data.ODataContext({
            url: "http://www.example.com/Northwind.svc",
            entities: {
                Categories: {
                    key: "CategoryID",
                    keyType: "Int32"
                },
                // An entity collection alias
                Clients: {
                    name: "Customers",
                    key: "CustomerID",
                    keyType: "String"
                },
                Products: {
                    // A composite key
                    key: ["ProductID", "ProductCode"],
                    keyType: {
                        ProductID: "Guid",
                        ProductCode: "Int32" 
                    }
                }
            }
        })
    });
Knockout
JavaScript
  
var viewModel = {
    context: new DevExpress.data.ODataContext({
        url: "http://www.example.com/Northwind.svc",
        entities: {
            Categories: {
                key: "CategoryID",
                keyType: "Int32"
            },
            // An entity collection alias
            Clients: {
                name: "Customers",
                key: "CustomerID",
                keyType: "String"
            },
            Products: {
                // A composite key
                key: ["ProductID", "ProductCode"],
                keyType: {
                    ProductID: "Guid",
                    ProductCode: "Int32" 
                }
            }
        }
    })
};

ko.applyBindings(viewModel);
See Also

Configuration

This section describes the ODataContext's configuration options.

Name Description
beforeSend

Specifies a function that customizes the request before it is sent to the server.

deserializeDates

Specifies whether stores in the ODataContext serialize/parse date-time values.

entities

Specifies entity collections to be accessed.

errorHandler

Specifies a function that is executed when the ODataContext throws an error.

jsonp

Specifies whether data should be sent using JSONP.

url

Specifies the URL of an OData service.

version

Specifies the OData version.

withCredentials

Specifies whether to send cookies, authorization headers, and client certificates in a cross-origin request.

Methods

This section describes the methods that control the ODataContext.

Name Description
get(operationName, params)

Invokes an OData operation that returns a value.

invoke(operationName, params, httpMethod)

Invokes an OData operation that returns nothing.

objectLink(entityAlias, key)

Gets a link to an entity with a specific key.