using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.OpenAccess;
using Model;

namespace _2_Concurrency
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      using (IObjectScope scope =
        Database.Get("NorthwindConnection").GetObjectScope())
      {
        scope.TransactionProperties.Concurrency =
          TransactionMode.PESSIMISTIC_EXPLICIT;
        scope.Transaction.Begin();

        Query<Order> query = scope.GetSqlQuery<Order>(
          "select * from orders where orderid = 10248",
          String.Empty);

        Order order = query.ExecuteList()[0];

        scope.Transaction.Lock(order, LockMode.WRITE);

        order.ShippedDate = DateTime.Now;

        scope.Add(order);

        scope.Transaction.Commit();
      }
    }
  }
}
