SmartDeviceProject1.SqlCeStorageHandler.TombstoneItem C# (CSharp) Method

TombstoneItem() public method

public TombstoneItem ( SqlCeOfflineEntity entity ) : void
entity SqlCeOfflineEntity
return void
        public void TombstoneItem(SqlCeOfflineEntity entity)
        {
            var item = (Item) entity;

            using (var connection = GetSqlCeConnection())
            {
                var transaction = connection.BeginTransaction();

                try
                {
                    using (var command = new SqlCeCommand())
                    {
                        command.Connection = connection;
                        command.CommandText = TOMBSTONE_TAGITEMMAPPING_FOR_ITEM;
                        command.Parameters.Add("@ItemID", SqlDbType.UniqueIdentifier).Value = item.ID;

                        command.ExecuteNonQuery();
                    }

                    using (var command = new SqlCeCommand())
                    {
                        command.Connection = connection;
                        command.CommandText = TOMBSTONE_ITEM;
                        command.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = item.ID;

                        command.ExecuteNonQuery();
                    }

                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }

Usage Example

Example #1
0
        private void menuItemDelete_Click(object sender, EventArgs e)
        {
            var item = ListBoxItems.SelectedItem as Item;

            if (null != item)
            {
                var storageHandler = new SqlCeStorageHandler();
                storageHandler.TombstoneItem(item);
            }

            RefreshItems();
        }