예제 #1
0
        /// <summary>
        /// Delete the provided object from the table
        /// </summary>
        /// <typeparam name="T">Type of business object</typeparam>
        /// <param name="item">Business object</param>
        /// <returns>Zero if nothing was deleted, One if the object was deleted</returns>
        public ulong Delete <T>(T item)
            where T : class
        {
            if (item != null)
            {
                // we need to check if we are soft-deleting!
                ClassInformation?objectInfo = TypeInspector.InspectForAzureTables <T>();
                if (objectInfo == null)
                {
                    throw new TypeLoadException($"Type '{typeof(T).FullName}' is not anotated with the '{typeof(TableAttribute).FullName}' attribute.");
                }

                TableAttribute   tableAttribute = objectInfo.TableAttribute;
                AzureTableEntity entity         = AzureTableEntity.From(item);
                TableOperation   updateOrDeleteOperation;

                if (tableAttribute.UseSoftDelete)
                {
                    entity.AddOrUpdateProperty(AzureTableEntity.PROPERTY_NAME_ISDELETED, true);
                    updateOrDeleteOperation = TableOperation.Merge(entity);
                }
                else
                {
                    updateOrDeleteOperation = TableOperation.Delete(entity);
                }

                ExecuteNonQuery <T>(updateOrDeleteOperation);
                return(1L);
            }

            return(0L);
        }
예제 #2
0
        /// <summary>
        /// Performs the actual UPDATE operation
        /// </summary>
        /// <typeparam name="T">Type of business object</typeparam>
        /// <param name="objects">Collection of objects</param>
        /// <param name="setSoftDeleteFlag">If TRUE, then we update the IsDeleted flag</param>
        private ulong UpdateInternal <T>(IEnumerable <T> objects, bool setSoftDeleteFlag = false)
            where T : class
        {
            if (objects != null)
            {
                TableBatchOperation update = new TableBatchOperation();
                foreach (T instance in objects)
                {
                    AzureTableEntity entity = AzureTableEntity.From(instance);
                    if (setSoftDeleteFlag)
                    {
                        entity.AddOrUpdateProperty(AzureTableEntity.PROPERTY_NAME_ISDELETED, true);
                    }
                    update.Merge(entity);
                }

                ulong count = (ulong)update.Count;
                if (count > 0)
                {
                    ExecuteNonQuery <T>(update);
                    return(count);
                }
            }

            return(0L);
        }