Пример #1
0
        public void UOW() // should be within one transaction unit
        {
            CustomerDbObject cust = new Customer();

            cust.CustomerName = "sample customer";
            CustomerDbObject lead = new Lead();

            lead.CustomerName = "sample lead";

            IRepositoryDAL <CustomerDbObject> dal = DALFactory.CreateCustomerDAL(DALType.ADOSQL);
            IUnitOfWork uow = new SQLUnitOfWork(GlobalConnectionString.ConnString);

            dal.SetUnitWork(uow);
            dal.Add(cust);
            try
            {
                uow.Commit();
            }
            catch (Exception)
            {
                uow.RollBack();
            }

            IRepositoryDAL <CustomerDbObject> dal2 = DALFactory.CreateCustomerDAL(DALType.EF);
            IUnitOfWork uow2 = new EFUnitOfWork(GlobalConnectionString.ConnString);

            dal2.SetUnitWork(uow2);
            dal2.Add(lead);
            dal2.Add(cust);
            try
            {
                uow2.Commit();
            }
            catch (Exception)
            {
                uow2.RollBack();
            }
        }