Share via


Sys.Data.DataContext Class

Provides facilities for read-write scenarios when using data providers such as WCF Web services or ADO.NET data services. The DataContext class supports change tracking and saving changes back to the service.

Namespace: Sys.Data

Inherits: Sys.Component

Implements: Sys.Data.IDataProvider

var MyDataContext = new Sys.Data.DataContext();

Constructors

Name

Description

Sys.Data.DataContext Constructor

Initializes a new instance the DataContext class.

Members

Name

Description

Sys.Data.DataContext.abortSave Method

Aborts the current Sys.Data.DataContext.saveChanges Method request.

Sys.Data.DataContext.addLink Method

Adds a link from one entity to another. Used in the case of many-to-many associations between entities.

Sys.Data.DataContext.clearChanges Method

Clears any tracked changes without committing them.

Sys.Data.DataContext.clearData Method

Clears the stored entities and clears tracked changes.

Sys.Data.DataContext.createEntity Method

Creates a JavaScript object for an entity of type entitySetName.

Sys.Data.DataContext.dispose Method

Disposes of the DataContext object.

Sys.Data.DataContext.fetchData Method

Fetches data from the provided service URI.

Sys.Data.DataContext.fetchDeferredProperty Method

Fetches data for a deferred property of an entity.

Sys.Data.DataContext.getIdentity Method

Gets the unique identity for an entity.

Sys.Data.DataContext.getNewIdentity Method

Generates a new identity for a new entity.

Sys.Data.DataContext.initialize Method

Called when the DataContext object is initialized.

Sys.Data.DataContext.insertEntity Method

Inserts a JavaScript object into the DataContext object. The DataContext object will then provide change tracking services on the object.

Sys.Data.DataContext.isDeferredProperty Method

Determines if the given entity and property name refer to a deferred link to another entity that has not been loaded yet.

Sys.Data.DataContext.removeEntity Method

Removes an entity from the Sys.Data.DataContext object, so that the object is no longer tracked by the DataContext for changes or identity management.

Sys.Data.DataContext.removeLink Method

Removes a link between two entities. Used in the case of many-to-many associations between entities.

Sys.Data.DataContext.saveChanges Method

Saves pending changes that were made to the current data being tracked by the Sys.Data.DataContext object.

Sys.Data.DataContext.setLink Method

Sets a link (or removes a link) between two entities. Used in the case of one-to-many associations between entities.

Sys.Data.DataContext.trackData Method

Loads the given data into the DataContext object as if it were loaded using the fetchData method.

Sys.Data.DataContext.updated Method

Called after the DataContext object has been initialized.

Sys.Data.DataContext.changes Property

Gets the current list of changes.

Sys.Data.DataContext.createEntityMethod Property

Gets or sets a JavaScript function used by the createEntity method for creating new entities.

Sys.Data.DataContext.fetchDataMethod Property

Gets or sets a JavaScript function used by the fetchData method to retrieve data.

Sys.Data.DataContext.getDeferredPropertyFetchOperationMethod Property

Gets or sets a JavaScript function used by the fetchDeferredProperty method to retrieve data. By setting this property you can provide a different implementation for fetching deferred properties.

Sys.Data.DataContext.getIdentityMethod Property

Gets or sets a JavaScript function used by the getIdentity method to provide a unique identity for an entity.

Sys.Data.DataContext.getNewIdentityMethod Property

Gets or sets a JavaScript function used by the getNewIdentity method to provide a new unique identity for an entity that has been created.

Sys.Data.DataContext.handleSaveChangesResultsMethod Property

Gets or sets the method that is called when a save operation completes.

Sys.Data.DataContext.hasChanges Property

Gets a boolean value indicating whether the DataContext has some changes on the objects which it is currently tracking.

Sys.Data.DataContext.isDeferredPropertyMethod Property

Gets or sets the method that determines if an entity field is currently a deferred entity link placeholder object.

Sys.Data.DataContext.isSaving Property

Gets a boolean value indicating whether the data is currently being saved.

Sys.Data.DataContext.items Property

Gets a dictionary of containing all the objects currently being tracked by the DataContext. The entities are keyed by their unique identities provided by the JavaScript function specified by the getIdentityMethod property.

Sys.Data.DataContext.lastFetchDataResults Property

Gets the last data that was retrieved successfully in a fetchData request.

Sys.Data.DataContext.mergeOption Property

Gets or sets a MergeOption value.

Sys.Data.DataContext.saveChangesMethod Property

Gets or sets a JavaScript function used by the saveChanges method to save data changes back to the service.

Sys.Data.DataContext.saveChangesTimeout Property

Gets or sets an integer representing a time limit used when saving changes.

Sys.Data.DataContext.saveHttpVerb Property

Gets or sets the HTTP method to be used by the Web request used for calling the saveChangesOperation on the service.

Sys.Data.DataContext.saveOperation Property

Gets or sets a string specifying the service operation to be used for saving changes.

Sys.Data.DataContext.saveParameters Property

Gets or sets a dictionary of parameters passed to the saveChangesOperation when saving changes.

Sys.Data.DataContext.serviceUri Property

Gets or sets a string indicating the service URI of the service to be used for retrieve data or for saving changes.

Example

The following example shows how to create a DataContext object and use it declaratively with a template.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">

<head>
    <title>Read-write, with DataContext</title>
    <link href="styles/list.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript" src="../MicrosoftAjax/MicrosoftAjax.debug.js"></script>
    <script type="text/javascript" src="../MicrosoftAjax/MicrosoftAjaxTemplates.debug.js"></script>
    <script type="text/javascript" src="../MicrosoftAjax/MicrosoftAjaxDataContext.debug.js"></script>
    <script type="text/javascript">
        var dataContext = $create(
            Sys.Data.DataContext,
            {
                serviceUri: "../Services/ImagesWcfService.svc",
                saveOperation: "SaveImages"
            }
        );
    </script>
 </head>

<body xmlns:sys="javascript:Sys"
      xmlns:dataview="javascript:Sys.UI.DataView"

    <ul class="list sys-template"
        sys:attach="dataview"
        dataview:autofetch="true"
        dataview:dataprovider="{{ dataContext }}"
        dataview:fetchoperation="GetImages"
        dataview:fetchparameters="{{ {orderBy: 'Name'} }}"
    >
        <li>
            <span>{{ Name }}</span>
            <span class="value">{{ Description }}</span>
        </li>
    </ul>
</body>
</html>

See Also

Other Resources

Language Reference