Esempio n. 1
0
        public static bool Update(T item)
        {
            if (table == null)
            {
                return(false);
            }

            try
            {
                PropertyInfo[] properties = item.GetType().GetProperties();

                ElasticTableEntity record = new ElasticTableEntity();

                BaseTable tbitem = item as BaseTable;
                record.RowKey       = tbitem.Id;
                record.PartitionKey = tbitem.Partition;
                record.ETag         = tbitem.Tag;

                foreach (PropertyInfo info in properties)
                {
                    record.Properties.Add(info.Name, EntityProperty.CreateEntityPropertyFromObject(info.GetValue(item, null)));
                }

                TableOperation replaceOperation = TableOperation.Replace(record);

                table.Execute(replaceOperation);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public static bool Insert(T item)
        {
            if (table == null)
            {
                return(false);
            }

            try
            {
                PropertyInfo[] properties = item.GetType().GetProperties();

                ElasticTableEntity record = new ElasticTableEntity();
                BaseTable          tbitem = item as BaseTable;
                record.RowKey       = (tbitem.Id == null) ? Guid.NewGuid().ToString() : tbitem.Id;
                record.PartitionKey = tbitem.Partition;
                record.ETag         = tbitem.Tag;

                foreach (PropertyInfo info in properties)
                {
                    var value = info.GetValue(item, null);
                    record.Properties.Add(info.Name, EntityProperty.CreateEntityPropertyFromObject(value));
                }


                TableOperation insertOrReplaceOperation = TableOperation.Insert(record);

                table.Execute(insertOrReplaceOperation);
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }