[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See
Storage Client Library for the latest version.]
Saves changes to the Table service, using the retry policy specified for the
TableServiceContext object, and a set of specified additional options for saving changes.
Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Usage
Visual Basic |
---|
Dim instance As TableServiceContext
Dim options As SaveChangesOptions
Dim returnValue As DataServiceResponse
returnValue = instance.SaveChangesWithRetries(options) |
Syntax
Visual Basic |
---|
Public Function SaveChangesWithRetries ( _
options As SaveChangesOptions _
) As DataServiceResponse |
C# |
---|
public DataServiceResponse SaveChangesWithRetries (
SaveChangesOptions options
) |
C++ |
---|
public:
DataServiceResponse^ SaveChangesWithRetries (
SaveChangesOptions options
) |
Parameters
- options
Type: System.Data.Services.Client.SaveChangesOptions
An object of type SaveChangesOptions that specifies additional options for saving changes to the Table service.
Return Value
Type:
System.Data.Services.Client.DataServiceResponseA
DataServiceResponse that represents the result of the operation.
Example
The following code example takes a DataTable object and writes the data in it to a table, using batch operations.
| Copy Code |
---|
// Bulk insert contacts from a DataTable object.
public static void BulkInsertContacts(DataTable dt)
{
// Ensure that the data table will be filtered case-insensitively.
dt.CaseSensitive = false;
// Add the data to the Contacts table using batch operations. Each batch consists of the contacts
// whose first name starts with the same letter of the alphabet (corresponding to the partition key).
for (char c = 'A'; c <= 'Z'; c++)
{
// Select all rows where FirstName begins with same letter.
DataRow[] rows = dt.Select("FirstName LIKE '" + c.ToString() + "*'", "FirstName ASC");
// Get data context.
TableServiceContext context = tableClient.GetDataServiceContext();
int i = 0;
// Create and add each entity.
foreach (DataRow row in rows)
{
ContactEntity contact = new ContactEntity();
contact.FirstName = row["FirstName"].ToString();
contact.LastName = dt.Columns.Contains("LastName") ? row["LastName"].ToString() : string.Empty;
contact.Email = dt.Columns.Contains("Email") ? row["Email"].ToString() : string.Empty;
contact.CellPhone = dt.Columns.Contains("CellPhone") ? row["CellPhone"].ToString() : string.Empty;
contact.HomePhone = dt.Columns.Contains("HomePhone") ? row["HomePhone"].ToString() : string.Empty;
contact.StreetAddress = dt.Columns.Contains("StreetAddress") ? row["StreetAddress"].ToString() : string.Empty;
contact.City = dt.Columns.Contains("City") ? row["City"].ToString() : string.Empty;
contact.State = dt.Columns.Contains("State") ? row["State"].ToString() : string.Empty;
contact.ZipCode = dt.Columns.Contains("ZipCode") ? row["ZipCode"].ToString() : string.Empty;
contact.PartitionKey = c.ToString();
contact.RowKey = contact.FirstName + "_" + Guid.NewGuid().ToString();
// Add the entity.
context.AddObject("Contacts", contact);
// Increment the counter.
i++;
// Batch supports only 100 transactions at a time, so if we hit 100 records for this partition,
// submit the transaction and keep going.
if (i == 100)
{
// Save changes, using the Batch option.
context.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions.Batch);
// Reset the counter.
i = 0;
}
}
// Save changes, using the Batch option.
context.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions.Batch);
}
}
public class ContactEntity : TableServiceEntity
{
public ContactEntity()
{
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string HomePhone { get; set; }
public string CellPhone { get; set; }
public string StreetAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
}
|
Remarks
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Change History
See Also