Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Delete the provided objects from the table.
        /// </summary>
        /// <typeparam name="T">Type of business object</typeparam>
        /// <param name="objects">Collection of objects</param>
        public ulong DeleteList <T>(IEnumerable <T> objects)
            where T : class
        {
            if (objects != 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.");
                }

                if (objectInfo.TableAttribute.UseSoftDelete)
                {
                    return(UpdateInternal(objects, true));
                }

                TableBatchOperation delete = new TableBatchOperation();
                foreach (T instance in objects)
                {
                    delete.Delete(AzureTableEntity.From(instance, true));
                }

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

            return(0L);
        }
Exemple #3
0
        /// <summary>
        /// Get the name of the table for the object
        /// </summary>
        /// <typeparam name="T">Class type of the business object</typeparam>
        /// <returns>Name of the table</returns>
        public static string GetTableName <T>() where T : class

#pragma warning disable CS8604 // Possible null reference argument.
        => entityTableNames.GetOrAdd(
            typeof(T).FullName,
            (objectName) =>
        {
            ClassInformation?objectInfo = TypeInspector.InspectForAzureTables <T>();
            if (objectInfo == null)
            {
                throw new TypeLoadException($"Type '{typeof(T).FullName}' is not anotated with the '{typeof(TableAttribute).FullName}' attribute.");
            }

            return(objectInfo.TableAttribute.TableName);
        }
            );