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 |
---|---|
Initializes a new instance the DataContext class. |
Members
Name |
Description |
---|---|
Aborts the current Sys.Data.DataContext.saveChanges Method request. |
|
Adds a link from one entity to another. Used in the case of many-to-many associations between entities. |
|
Clears any tracked changes without committing them. |
|
Clears the stored entities and clears tracked changes. |
|
Creates a JavaScript object for an entity of type entitySetName. |
|
Disposes of the DataContext object. |
|
Fetches data from the provided service URI. |
|
Fetches data for a deferred property of an entity. |
|
Gets the unique identity for an entity. |
|
Generates a new identity for a new entity. |
|
Called when the DataContext object is initialized. |
|
Inserts a JavaScript object into the DataContext object. The DataContext object will then provide change tracking services on the object. |
|
Determines if the given entity and property name refer to a deferred link to another entity that has not been loaded yet. |
|
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. |
|
Removes a link between two entities. Used in the case of many-to-many associations between entities. |
|
Saves pending changes that were made to the current data being tracked by the Sys.Data.DataContext object. |
|
Sets a link (or removes a link) between two entities. Used in the case of one-to-many associations between entities. |
|
Loads the given data into the DataContext object as if it were loaded using the fetchData method. |
|
Called after the DataContext object has been initialized. |
|
Gets the current list of changes. |
|
Gets or sets a JavaScript function used by the createEntity method for creating new entities. |
|
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. |
Gets or sets a JavaScript function used by the getIdentity method to provide a unique identity for an entity. |
|
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. |
Gets a boolean value indicating whether the DataContext has some changes on the objects which it is currently tracking. |
|
Gets or sets the method that determines if an entity field is currently a deferred entity link placeholder object. |
|
Gets a boolean value indicating whether the data is currently being saved. |
|
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. |
|
Gets the last data that was retrieved successfully in a fetchData request. |
|
Gets or sets a MergeOption value. |
|
Gets or sets a JavaScript function used by the saveChanges method to save data changes back to the service. |
|
Gets or sets an integer representing a time limit used when saving changes. |
|
Gets or sets the HTTP method to be used by the Web request used for calling the saveChangesOperation on the service. |
|
Gets or sets a string specifying the service operation to be used for saving changes. |
|
Gets or sets a dictionary of parameters passed to the saveChangesOperation when saving changes. |
|
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>