public CommandEntity Retrieve(string containerName, string id, RepositoryEntityMetadata metadata)
        {
            containerName.GuardAgainstNullOrEmpty(nameof(containerName));
            id.GuardAgainstNull(nameof(id));
            metadata.GuardAgainstNull(nameof(metadata));

            var table = EnsureTable(containerName);

            var tableEntity = RetrieveTableEntitySafe(table, id);

            return(tableEntity != null
                ? CommandEntity.FromCommandEntity(tableEntity.FromTableEntity(metadata, this.options), metadata)
                : default);
예제 #2
0
        public CommandEntity Replace(string containerName, string id, CommandEntity entity)
        {
            containerName.GuardAgainstNullOrEmpty(nameof(containerName));
            id.GuardAgainstNull(nameof(id));
            entity.GuardAgainstNull(nameof(entity));

            var container = EnsureContainer(containerName);

            var result = container.UpsertItemAsync <dynamic>(entity.ToContainerEntity()).GetAwaiter().GetResult();

            return(CommandEntity.FromCommandEntity(((JObject)result.Resource).FromContainerEntity(entity.Metadata),
                                                   entity));
        }
        public CommandEntity Retrieve(string tableName, string id, RepositoryEntityMetadata metadata)
        {
            tableName.GuardAgainstNullOrEmpty(nameof(tableName));
            id.GuardAgainstNull(nameof(id));
            metadata.GuardAgainstNull(nameof(metadata));

            var tableEntity =
                ExecuteSingleSelect($"SELECT * FROM {tableName} WHERE {nameof(CommandEntity.Id)}='{id}'");

            if (tableEntity != null)
            {
                return(CommandEntity.FromCommandEntity(tableEntity.FromTableEntity(metadata), metadata));
            }

            return(default);
        public CommandEntity Replace(string containerName, string id, CommandEntity entity)
        {
            containerName.GuardAgainstNullOrEmpty(nameof(containerName));
            id.GuardAgainstNull(nameof(id));
            entity.GuardAgainstNull(nameof(entity));

            var client = EnsureClient();

            var keyValues = entity.ToContainerProperties();
            var key       = CreateRowKey(containerName, id);

            client.Remove(key);
            client.SetRangeInHash(key, keyValues);

            return(CommandEntity.FromCommandEntity(keyValues.FromContainerProperties(id, entity.Metadata), entity));
        }
        public CommandEntity Retrieve(string containerName, string id, RepositoryEntityMetadata metadata)
        {
            containerName.GuardAgainstNullOrEmpty(nameof(containerName));
            id.GuardAgainstNull(nameof(id));
            metadata.GuardAgainstNull(nameof(metadata));

            var client = EnsureClient();

            var rowKey = CreateRowKey(containerName, id);

            var properties = GetEntityFromContainer(client, rowKey, metadata);

            return(properties == null
                ? null
                : CommandEntity.FromCommandEntity(properties, metadata));
        }
예제 #6
0
        private static CommandEntity RetrieveContainerEntitySafe(Container container, string id,
                                                                 RepositoryEntityMetadata metadata)

        {
            try
            {
                var entity = container.ReadItemAsync <object>(id, new PartitionKey(id))
                             .GetAwaiter()
                             .GetResult();
                return(CommandEntity.FromCommandEntity(
                           ((JObject)entity?.Resource)?.FromContainerEntity(metadata),
                           metadata));
            }
            catch (Exception)
            {
                return(default);