AzurePatterns.TableStorage.TableStorageContext.Commit C# (CSharp) Метод

Commit() публичный Метод

public Commit ( ) : void
Результат void
        public void Commit()
        {
            try
            {
                // Insert or Merge Entity aka Upsert (>=v.1.4) uses
                // SaveChangesOptions.None to generate a merge request.
                this.SaveChanges(SaveChangesOptions.None);
            }
            catch (DataServiceRequestException exception)
            {
                var dataServiceClientException = exception.InnerException as DataServiceClientException;
                if (dataServiceClientException != null)
                {
                    if (dataServiceClientException.StatusCode == (int)HttpStatusCode.Conflict)
                    {
                        // a conflict may arise on a retry where it succeeded so this is ignored.
                        // TODO: this should be a list of codes to check and ignore/log/retry etc.
                        return;
                    }
                }

                throw;
            }
        }

Usage Example

        // NOTE: Windows Azure changes a lot with each release.
        // This code was written against version 1.7 (June 2012).
        public void ShouldAlterEntity()
        {
            // NOTE: expect the context and the repository to be managed by your IoC container.
            var context = new TableStorageContext();
            var entityRepository = new EntityRepository(context);

            var partitionKey = new ByPartitionKeySpecification("partitionKey");
            var rowKey = new ByRowKeySpecification("rowKey");

            var entity = entityRepository.GetEntity(partitionKey, rowKey);

            //// make some change to entity ...

            entityRepository.Save(entity);

            context.Commit();
        }