private void buttonAdd_Click(object sender, EventArgs e)
        {
            // Add a new Order in a child transaction scope.
            // Rolling back the child transaction will not roll back the parent transaction.
            using (var tran2 = new ClientTransaction(_transaction))
            {
                var order = new Order();
                using (tran2.Scope())
                {
                    _cache.ObjectContext.AddObject("Orders", order);
                }


                var window = new OrderForm(order, tran2);
                if (window.ShowDialog() == DialogResult.OK)
                {
                    // Add the order to the Customer.Orders in the child transaction scope and commit the transaction.
                    using (tran2.Scope())
                    {
                        Customer.Orders.Add(order);
                        tran2.Commit();
                    }
                }
            } // The child transaction will be rolled back automatically if it is not committed.
        }
        public MainWindow()
        {
            InitializeComponent();

            // Initialize the default client cache and open the global transaction scope,
            // so all changes in the application are made in a transaction.
            _cache            = C1.Data.Entities.EntityClientCache.GetDefault(typeof(NORTHWNDEntities));
            _transaction      = _cache.CreateTransaction();
            _transactionScope = _transaction.Scope();
        }
 void CancelAllChanges(object sender, RoutedEventArgs e)
 {
     // Cancel all changes made in this application by rolling back the global transaction.
     if (_transaction.State == TransactionState.Open)
     {
         _transaction.Rollback();
         _transactionScope.Dispose();
     }
     // Open a new transaction.
     _transaction      = _cache.CreateTransaction();
     _transactionScope = _transaction.Scope();
 }
Ejemplo n.º 4
0
        private void deleteOrder(object sender, RoutedEventArgs e)
        {
            // Remove the selected order.

            var order = ordersGrid.SelectedItem as OrderInfo;

            if (order == null)
            {
                return;
            }
            using (_transaction.Scope())
            {
                // Make the change in the transaction scope.
                Customer.Orders.Remove(order.GetOrder());
            }
        }
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            // Remove the selected order.

            var row = BindingContext[_ordersView].Current as C1.LiveLinq.LiveViews.ViewRow;

            if (row == null)
            {
                return;
            }
            var order = ((OrderInfo)row.Value).GetOrder();

            using (_transaction.Scope())
            {
                // Make the change in the transaction scope.
                Customer.Orders.Remove(order);
            }
        }
Ejemplo n.º 6
0
 private void addOrder(object sender, RoutedEventArgs e)
 {
     // Add a new Order in a child transaction scope.
     // Rolling back the child transaction will not roll back the parent transaction.
     using (var tran2 = new ClientTransaction(_transaction)) // Create a child transaction.
     {
         var order  = new Order();
         var window = new OrderWindow(order, tran2);
         if (window.ShowDialog() == true)
         {
             // Add the order in the child transaction scope and commit the transaction.
             using (tran2.Scope())
             {
                 Customer.Orders.Add(order);
                 tran2.Commit();
             }
         }
     } // The child transaction will be rolled back automatically if it is not committed.
 }