public void PgDataTypeTest()
		{
            DateTime testTime = Convert.ToDateTime("0001-01-01 01:23:45.678");
            PgDataTypes datatypeTest = new PgDataTypes();

            switch (datatypeTest.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.Npgsql2Provider":
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        datatypeTest.TimeType = testTime;
                        datatypeTest.Save();

                        long? tempKey = datatypeTest.Id;

                        datatypeTest = new PgDataTypes();
                        Assert.IsTrue(datatypeTest.LoadByPrimaryKey(tempKey.Value));
                        Assert.IsTrue(datatypeTest.TimeType.HasValue);
                        Assert.AreEqual(datatypeTest.TimeType.Value, testTime);
                        datatypeTest.MarkAsDeleted();
                        datatypeTest.Save();
                    }
					break;

				default:
					Assert.Ignore("PostgreSQL only");
					break;
			}
		}
		public void SetGuidPrimaryKey()
		{
            GuidTest dataTest = new GuidTest();
            dataTest.es.Connection.Name = "GuidTest";

            switch (dataTest.es.Connection.ProviderMetadataKey)
            {
                case "esSqlCe":
                case "esSqlCe4":
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        string testGuid = "b3883c65-ff94-47c4-8b0c-76896bedd45a";
                        dataTest = new GuidTest();
                        dataTest.es.Connection.Name = "GuidTest";
                        dataTest.GuidKey = new Guid(testGuid);
                        dataTest.Save();
                        Guid? tempKey = dataTest.GuidKey;
                        dataTest.MarkAsDeleted();
                        dataTest.Save();
                        Assert.AreEqual(testGuid, tempKey.Value.ToString());
                    }
                    break;

                default:
                    Assert.Ignore("SqlCe only");
                    break;
            }
		}
示例#3
0
        /// <summary>
        /// You should never call this directly, the providers call this method.
        /// </summary>
        /// <param name="cmd">The command to enlist into a transaction</param>
        static public void DeEnlist(IDbCommand cmd)
        {
            esTransactionScope current = GetCurrentTx();

            if (current == null || current.option == esTransactionScopeOption.Suppress)
            {
                cmd.Connection.Close();
            }
        }
        public void ConcurrencyOnUpdate()
        {
            ComputedTestCollection collection = new ComputedTestCollection();
            int testId = 0;

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SybaseSqlAnywhereProvider":
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            // Setup
                            ComputedTest entity = new ComputedTest();
                            entity.Save();
                            testId = entity.Id.Value;

                            // Test
                            entity = new ComputedTest();
                            entity.LoadByPrimaryKey(testId);
                            entity.str().SomeDate = "2007-01-01";

                            ComputedTest entity2 = new ComputedTest();
                            entity2.LoadByPrimaryKey(testId);
                            entity2.str().SomeDate = "1999-12-31";

                            entity.Save();
                            entity2.Save();
                            Assert.Fail("Concurrency Exception not thrown.");
                        }
                    }
                    catch (EntitySpaces.Interfaces.esConcurrencyException cex)
                    {
                        string err = cex.InnerException.Message.Substring(0, 11);
                        Assert.AreEqual("Error", cex.Message.Substring(0, 5));
                        Assert.AreEqual("Concurrency", err);
                    }
                    finally
                    {
                        ComputedTest entity = new ComputedTest();
                        if (entity.LoadByPrimaryKey(testId))
                        {
                            entity.MarkAsDeleted();
                            entity.Save();
                        }
                    }
                    break;

                default:
                    Assert.Ignore("Sybase only.");
                    break;
            }
        }
示例#5
0
        /// <summary>
        /// This can be used to get the esTransactionScopeOption from the current esTransactionScope (remember transactions can be nested).
        /// If there is no on-going transaction then esTransactionScopeOption.None is returned.
        /// </summary>
        /// <returns></returns>
        static public esTransactionScopeOption GetCurrentTransactionScopeOption()
        {
            esTransactionScope currentTx = GetCurrentTx();

            if (currentTx == null)
            {
                return(esTransactionScopeOption.None);
            }
            else
            {
                return(currentTx.option);
            }
        }
        public void SaveComposite()
        {
            using (esTransactionScope scope = new esTransactionScope())
            {
                OrderItemCollection coll = new OrderItemCollection();
                coll.es.Connection.Name = "ForeignKeyTest";

                OrderItem entity = coll.AddNew();
                entity.OrderID = 9;
                entity.ProductID = 1;
                entity.UnitPrice = 1000;
                entity.Quantity = 1000;
                entity = coll.AddNew();
                entity.OrderID = 9;
                entity.ProductID = 2;
                entity.UnitPrice = 1000;
                entity.Quantity = 1000;
                entity = coll.AddNew();
                entity.OrderID = 9;
                entity.ProductID = 3;
                entity.UnitPrice = 1000;
                entity.Quantity = 1000;

                coll.Save();

                coll = new OrderItemCollection();
                coll.es.Connection.Name = "ForeignKeyTest";

                coll.Query.Where(coll.Query.OrderID == 9);
                Assert.IsTrue(coll.Query.Load());
                Assert.AreEqual(3, coll.Count);

                // Clean up
                coll.MarkAllAsDeleted();
                coll.Save();

                coll = new OrderItemCollection();
                coll.es.Connection.Name = "ForeignKeyTest";

                coll.Query.Where(coll.Query.OrderID == 9);
                Assert.IsFalse(coll.Query.Load());

                coll = new OrderItemCollection();
                coll.es.Connection.Name = "ForeignKeyTest";

                Assert.IsTrue(coll.LoadAll());
                Assert.AreEqual(15, coll.Count);
            }
        }
		public void MySQLNumericTypeTest()
		{
			MysqltypetestCollection datatypeTestColl = new MysqltypetestCollection();
			Mysqltypetest datatypeTest = new Mysqltypetest();

			// There is a bug in the 1.0.7 Connector/Net for unsigned types.
			// It is fixed in 5.0.3.
            switch (datatypeTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.MySqlClientProvider":
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        datatypeTest.BigIntType = -1;
                        datatypeTest.BigIntUType = 1;
                        datatypeTest.DblType = -1;
                        datatypeTest.DblUType = 1;
                        datatypeTest.DecType = (decimal)(-1.5);
                        datatypeTest.DecUType = (decimal)(1.5);
                        datatypeTest.FloatType = (float)(-1.5);
                        datatypeTest.FloatUType = (float)(1.5);
                        datatypeTest.IntType = -1;
                        datatypeTest.IntUType = 1;
                        datatypeTest.MedIntType = -1;
                        datatypeTest.MedIntUType = 1;
                        datatypeTest.NumType = (decimal)(-1.5);
                        datatypeTest.NumUType = (decimal)(1.5);
                        datatypeTest.RealType = -1.5;
                        datatypeTest.RealUType = 1.5;
                        datatypeTest.SmallIntType = -1;
                        datatypeTest.SmallIntUType = 1;
                        datatypeTest.TinyIntType = (sbyte)(1);
                        datatypeTest.TinyIntUType = Convert.ToByte(1);

                        datatypeTest.Save();

                        int? tempKey = datatypeTest.Id;
                        Assert.IsTrue(datatypeTest.LoadByPrimaryKey(tempKey.Value));
                        datatypeTest.MarkAsDeleted();
                        datatypeTest.Save();
                    }
					break;

				default:
					Assert.Ignore("MySQL only");
					break;
			}
		}
示例#8
0
        /// <summary>
        /// You should never call this directly, the providers call this method.
        /// </summary>
        /// <param name="cmd">The command to enlist into a transaction</param>
        /// <param name="connectionString">The connection string passed to the CreateIDbConnectionDelegate delegate</param>
        /// <param name="creator">The delegate previously registered by the provider</param>
        static public void Enlist(IDbCommand cmd, string connectionString, CreateIDbConnectionDelegate creator)
        {
            esTransactionScope currentTx = GetCurrentTx();

            if (currentTx == null || currentTx.option == esTransactionScopeOption.Suppress)
            {
                cmd.Connection = creator();
                cmd.Connection.ConnectionString = connectionString;
                cmd.Connection.Open();
            }
            else
            {
                Transaction tx = null;

                if (currentTx.root.transactions.ContainsKey(connectionString))
                {
                    tx = currentTx.root.transactions[connectionString] as Transaction;
                }
                else
                {
                    tx = new Transaction();

                    IDbConnection cn = creator();
                    cn.ConnectionString = connectionString;
                    cn.Open();

                    // The .NET framework has a bug in that the IDbTransaction only maintains
                    // a weak reference to the Connection, thus, we put a strong reference
                    // on it.
                    tx.sqlCn = cn;

                    if (_isolationLevel != IsolationLevel.Unspecified)
                    {
                        tx.sqlTx = cn.BeginTransaction(_isolationLevel);
                    }
                    else
                    {
                        tx.sqlTx = cn.BeginTransaction();
                    }

                    currentTx.root.transactions[connectionString] = tx;
                }

                cmd.Connection  = tx.sqlTx.Connection;
                cmd.Transaction = tx.sqlTx;
            }
        }
示例#9
0
        /// <summary>
        /// Internal method.
        /// </summary>
        /// <returns></returns>
        static private esTransactionScope GetCurrentTx()
        {
            esTransactionScope tx = null;

            object o = Thread.GetData(txSlot);

            if (o != null)
            {
                Stack <esTransactionScope> stack = o as Stack <esTransactionScope>;
                if (stack.Count > 0)
                {
                    tx = stack.Peek();
                }
            }

            return(tx);
        }
		public void TestSaveWithAutoKey()
		{
            int terrKey = -1;
            Territory terr = new Territory();
            terr.es.Connection.Name = "ForeignKeyTest";
            TerritoryEx terrEx = new TerritoryEx();
            terrEx.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    terr.Description = "Some New Territory";

                    terrEx = terr.TerritoryEx;
                    terrEx.Notes = "Test Group";

                    terr.Save();

                    terrKey = terr.TerritoryID.Value;

                    Assert.IsTrue(terr.TerritoryEx.es.HasData);
                    Assert.AreEqual(terr.TerritoryID.Value, terrEx.TerritoryID.Value);

                    terr = new Territory();
                    terr.es.Connection.Name = "ForeignKeyTest";

                    Assert.IsTrue(terr.LoadByPrimaryKey(terrKey));
                    Assert.IsTrue(terr.TerritoryEx.es.HasData);
                }
            }
            finally
            {
                // Clean up
                terr = new Territory();
                terr.es.Connection.Name = "ForeignKeyTest";

                if (terr.LoadByPrimaryKey(terrKey))
                {
                    terrEx = terr.TerritoryEx;
                    terrEx.MarkAsDeleted();
                    terr.MarkAsDeleted();
                    terr.Save();
                }
            }
		}
示例#11
0
        /// <summary>
        /// This is the common constructor logic, tx is "this" from the constructor
        /// </summary>
        /// <param name="tx"></param>
        static protected void CommonInit(esTransactionScope tx)
        {
            Stack <esTransactionScope> stack;

            // See if our stack is already created (there is only one per thread)
            object obj = Thread.GetData(txSlot);

            if (obj == null)
            {
                stack = new Stack <esTransactionScope>();
                Thread.SetData(txSlot, stack);
            }
            else
            {
                stack = (Stack <esTransactionScope>)obj;
            }

            // If this transaction is required we need to set it's root
            if (tx.option == esTransactionScopeOption.Required)
            {
                foreach (esTransactionScope esTrans in stack)
                {
                    // The root can be either a Requires or RequiresNew, and a root always points to
                    // itself, therefore, as long as it's not a Suppress and it's pointing to itself
                    // then we know this the next root up on the stack
                    if (esTrans.option != esTransactionScopeOption.Suppress && esTrans == esTrans.root)
                    {
                        tx.root = esTrans;
                        break;
                    }
                }
            }

            // If we didn't find a root, then we are by definition the root
            if (tx.root == null)
            {
                tx.root         = tx;
                tx.transactions = new Dictionary <string, Transaction>();
            }

            stack.Push(tx);
        }
		public void TestTransactions()
		{
			switch (aggTest.es.Connection.Name)
			{
				case "SQLStoredProcEnterprise":
				case "SQLDynamicEnterprise":
				case "ORACLEStoredProcEnterprise":
				case "ORACLEDynamicEnterprise":
				case "VistaDBDynamic":
					Assert.Ignore("Using esTransactionScope only");
					break;

				default:
                    int tempId1 = 0;
                    int tempId2 = 0;

                    aggTest = new AggregateTest();
                    AggregateTest aggTest2 = new AggregateTest();

                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        aggTest.Save();
                        tempId1 = aggTest.Id.Value;
                        aggTest2.Save();
                        tempId2 = aggTest2.Id.Value;

                        scope.Complete();
                    }

                    aggTest = new AggregateTest();
                    Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId1));
                    aggTest.MarkAsDeleted();
                    aggTest.Save();

                    aggTest = new AggregateTest();
                    Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId2));
                    aggTest.MarkAsDeleted();
                    aggTest.Save();

					break;
			}
		}
示例#13
0
        /// <summary>
        /// You should never call this directly, EntitySpaces calls this internally.
        /// </summary>
        /// <param name="commit">Any class that implements ICommittable</param>
        /// <returns>True if successful</returns>
        static public bool AddForCommit(ICommittable commit)
        {
            esTransactionScope current = GetCurrentTx();

            if (current != null)
            {
                if (current.commitList == null)
                {
                    current.commitList = new List <ICommittable>();
                }

                current.commitList.Add(commit);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void TestDateTime()
        {
            int testId = -1;
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
            AggregateTest           test        = new AggregateTest();

            try
            {
                using (EntitySpaces.Interfaces.esTransactionScope scope =
                           new EntitySpaces.Interfaces.esTransactionScope())
                {
                    aggTestColl.Query.Load();
                    aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);
                    test = (AggregateTest)aggTestColl[0];
                    DateTime date = test.HireDate.Value;
                    Assert.AreEqual(Convert.ToDateTime("02/16/2000 05:59:31"), date);

                    test          = new AggregateTest();
                    test.HireDate = Convert.ToDateTime("12/31/9999");
                    test.Save();
                    testId = test.Id.Value;

                    test = new AggregateTest();
                    Assert.IsTrue(test.LoadByPrimaryKey(testId));
                    Assert.AreEqual(Convert.ToDateTime("12/31/9999"), test.HireDate.Value);
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
            finally
            {
                // Clean up
                test = new AggregateTest();
                if (test.LoadByPrimaryKey(testId))
                {
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
        }
		public void TestDateTime()
		{
            int testId = -1;
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
            AggregateTest test = new AggregateTest();

            try
            {
                using (EntitySpaces.Interfaces.esTransactionScope scope =
                    new EntitySpaces.Interfaces.esTransactionScope())
                {
                    aggTestColl.Query.Load();
                    aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);
                    test = (AggregateTest)aggTestColl[0];
                    DateTime date = test.HireDate.Value;
                    Assert.AreEqual(Convert.ToDateTime("02/16/2000 05:59:31"), date);

                    test = new AggregateTest();
                    test.HireDate = Convert.ToDateTime("12/31/9999");
                    test.Save();
                    testId = test.Id.Value;

                    test = new AggregateTest();
                    Assert.IsTrue(test.LoadByPrimaryKey(testId));
                    Assert.AreEqual(Convert.ToDateTime("12/31/9999"), test.HireDate.Value);
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
            finally
            {
                // Clean up
                test = new AggregateTest();
                if (test.LoadByPrimaryKey(testId))
                {
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
		}
        public void DataTypeVarCharMax()
        {
            SqlServerTypeTest dataTest = new SqlServerTypeTest();

            switch (dataTest.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlClientProvider":
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        dataTest = new SqlServerTypeTest();

                        Assert.AreEqual(0, dataTest.es.ModifiedColumns.Count, "Count1");
                        dataTest.VarCharMaxType = "Test";
                        Assert.AreEqual(1, dataTest.es.ModifiedColumns.Count, "Count2");
                        dataTest.Save();
                        long tempKey = dataTest.Id.Value;

                        dataTest = new SqlServerTypeTest();
                        Assert.IsTrue(dataTest.LoadByPrimaryKey(tempKey));
                        Assert.AreEqual("Test", dataTest.VarCharMaxType);

                        Assert.AreEqual(0, dataTest.es.ModifiedColumns.Count, "Count3");
                        dataTest.VarCharMaxType = dataTest.VarCharMaxType;
                        Assert.AreEqual(0, dataTest.es.ModifiedColumns.Count, "Count4");

                        // Clean up
                        dataTest.MarkAsDeleted();
                        dataTest.Save();
                    }
                    break;

                default:
                    Assert.Ignore("Sql Server only");
                    break;
            }
        }
示例#17
0
        protected override void LinqQueryPageTest(int count, int pageSize)
        {
            using (var ts = new esTransactionScope())
            {
                for (var i = 0; i < count; i++)
                {
                    var id = (i * pageSize) % InstanceCount;
                    var simplests = new SimplestsCollection();
                    simplests.Load(_db, _pageQuery(_db, id, pageSize));
                    foreach (var o in simplests)
                    {
                        // Doing nothing, just enumerate
                    }
                }

                ts.Complete();
            }
        }
示例#18
0
 protected override void NativeMaterializeTest(int count)
 {
     using (var ts = new esTransactionScope())
     {
         var simplests = new SimplestsCollection();
         int i = 0;
         while (i < count)
         {
             simplests.LoadAll();
             foreach (var o in simplests)
                 if (++i >= count)
                     break;
         }
         ts.Complete();
     }
 }
示例#19
0
 protected override void LinqMaterializeTest(int count)
 {
     using (var ts = new esTransactionScope())
     {
         var simplests = new SimplestsCollection();
         int i = 0;
         while (i < count)
         {
             simplests.Load(_db, _db.GetTable<Simplests>().Where(o => o.Id > 0));
             foreach (var o in simplests)
                 if (++i >= count)
                     break;
         }
         ts.Complete();
     }
 }
示例#20
0
 protected override void NativeQueryTest(int count)
 {
     using (var ts = new esTransactionScope())
     {
         for (int i = 0; i < count; i++)
         {
             var simplests = new SimplestsCollection();
             var id = i % InstanceCount;
             simplests.Query.Where(simplests.Query.Id == id);
             if (simplests.Query.Load())
                 foreach (var simplest in simplests)
                 {
                     // Doing nothing, just enumerate
                 }
         }
         ts.Complete();
     }
 }
示例#21
0
 protected override void CompiledLinqQueryTest(int count)
 {
     using (var ts = new esTransactionScope())
     {
         for (int i = 0; i < count; i++)
         {
             var id = i % InstanceCount;
             var query = new SimplestsCollection();
             query.Load(_db, _compiledQuery(_db, id));
             foreach (var simplest in query)
             {
                 // Doing nothing, just enumerate
             }
         }
         ts.Complete();
     }
 }
示例#22
0
 protected override void FetchTest(int count)
 {
     long sum = (long) count * (count - 1) / 2;
     using (var ts = new esTransactionScope())
     {
         for (int i = 0; i < count; i++)
         {
             var id = (long) i % InstanceCount;
             var simplest = new Simplests();
             simplest.LoadByPrimaryKey(id);
             sum -= simplest.Id.Value;
         }
         ts.Complete();
     }
     if (count <= InstanceCount)
         Assert.AreEqual(0, sum);
 }
示例#23
0
 protected override void DeleteSingleTest()
 {
     using (var ts = new esTransactionScope())
     {
         var simplests = new SimplestsCollection();
         simplests.LoadAll();
         for (int i = simplests.Count - 1; i >= 0; i--)
         {
             var o = simplests[0];
             o.MarkAsDeleted();
             o.Save();
         }
         ts.Complete();
     }
 }
示例#24
0
 protected override void UpdateSingleTest()
 {
     using (var ts = new esTransactionScope())
     {
         var simplests = new SimplestsCollection();
         simplests.LoadAll();
         foreach (var o in simplests)
         {
             o.Value++;
             o.Save();
         }
         ts.Complete();
     }
 }
示例#25
0
 protected override void InsertSingleTest(int count)
 {
     using (var ts = new esTransactionScope())
     {
         for (int i = 0; i < count; i++)
         {
             var simplest = new Simplests
             {
                 Id = i,
                 Value = i
             };
             simplest.Save();
         }
         ts.Complete();
     }
     InstanceCount = count;
 }
        public void ConcurrencyOnUpdateDeleteAutoKey()
        {
            long oldKey = -1;
            ConcurrencyTestChildCollection collection = new ConcurrencyTestChildCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlServerCeProvider":
                case "EntitySpaces.SqlServerCe4Provider":
                    Assert.Ignore("Not implemented for SqlCe");
                    break;

                default:
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            // Setup
                            ConcurrencyTestChild entity = new ConcurrencyTestChild();
                            entity.Name = "Test 1";
                            entity.DefaultTest = Convert.ToDateTime("2010-01-01");
                            entity.Save();
                            oldKey = entity.Id.Value;

                            // Test
                            entity = new ConcurrencyTestChild();
                            entity.LoadByPrimaryKey(oldKey);
                            entity.Name = "Test 2";

                            ConcurrencyTestChild entity2 = new ConcurrencyTestChild();
                            entity2.LoadByPrimaryKey(oldKey);
                            entity2.MarkAsDeleted();

                            entity.Save();
                            entity2.Save();
                            Assert.Fail("Concurrency Exception not thrown.");
                        }
                    }
                    catch (EntitySpaces.Interfaces.esConcurrencyException cex)
                    {
                        switch (collection.es.Connection.ProviderSignature.DataProviderName)
                        {
                            case "EntitySpaces.MSAccessProvider":
                            case "EntitySpaces.MySqlClientProvider":
                            case "EntitySpaces.SQLiteProvider":
                            case "EntitySpaces.SqlServerCeProvider":
                            case "EntitySpaces.SybaseSqlAnywhereProvider":
                            case "EntitySpaces.VistaDBProvider":
                            case "EntitySpaces.VistaDB4Provider":
                                Assert.AreEqual("Error in", cex.Message.Substring(0, 8));
                                break;

                            case "EntitySpaces.OracleClientProvider":
                                Assert.AreEqual("ORA-20101", cex.Message.Substring(0, 9));
                                break;

                            default:
                                Assert.AreEqual("Update failed", cex.Message.Substring(0, 13));
                                break;
                        }
                    }
                    finally
                    {
                        // Cleanup
                        ConcurrencyTestChild entity = new ConcurrencyTestChild();
                        if (entity.LoadByPrimaryKey(oldKey))
                        {
                            entity.MarkAsDeleted();
                            entity.Save();
                        }
                    }
                    break;
            }
        }
        static private DataTable SaveDynamicCollection_Deletes(esDataRequest request)
        {
            SACommand cmd = null;

            DataTable dataTable = CreateDataTable(request);

            using (esTransactionScope scope = new esTransactionScope())
            {
                using (SADataAdapter da = new SADataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                    try
                    {
                        da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                        cmd = da.DeleteCommand = Shared.BuildDynamicDeleteCommand(request, request.CollectionSavePacket[0]);
                        esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);

                        DataRow[] singleRow = new DataRow[1];

                        // Delete each record
                        foreach (esEntitySavePacket packet in request.CollectionSavePacket)
                        {
                            DataRow row = dataTable.NewRow();
                            dataTable.Rows.Add(row);

                            SetOriginalValues(request, packet, row, true);
                            row.AcceptChanges();
                            row.Delete();

                            singleRow[0] = row;
                            da.Update(singleRow);

                            if (row.HasErrors)
                            {
                                request.FireOnError(packet, row.RowError);
                            }

                            dataTable.Rows.Clear(); // ADO.NET won't let us reuse the same DataRow
                        }
                    }
                    finally
                    {
                        esTransactionScope.DeEnlist(cmd);
                    }
                }
                scope.Complete();
            }

            return request.Table;
        }
        /// <summary>
        /// This is the common constructor logic, tx is "this" from the constructor
        /// </summary>
        /// <param name="tx"></param>
        static protected void CommonInit(esTransactionScope tx)
        {
            Stack<esTransactionScope> stack;

            // See if our stack is already created (there is only one per thread)
            object obj = Thread.GetData(txSlot);
            if (obj == null)
            {
                stack = new Stack<esTransactionScope>();
                Thread.SetData(txSlot, stack);
            }
            else
            {
                stack = (Stack<esTransactionScope>)obj;
            }

            // If this transaction is required we need to set it's root
            if (tx.option == esTransactionScopeOption.Required)
            {
                foreach (esTransactionScope esTrans in stack)
                {
                    // The root can be either a Requires or RequiresNew, and a root always points to
                    // itself, therefore, as long as it's not a Suppress and it's pointing to itself
                    // then we know this the next root up on the stack
                    if (esTrans.option != esTransactionScopeOption.Suppress && esTrans == esTrans.root)
                    {
                        tx.root = esTrans;
                        break;
                    }
                }
            }

            // If we didn't find a root, then we are by definition the root
            if (tx.root == null)
            {
                tx.root = tx;
                tx.transactions = new Dictionary<string, Transaction>();
            }

            stack.Push(tx);
        }
示例#29
0
        private static DataTable SaveDynamicCollection_InsertsUpdates(esDataRequest request)
        {
            DataTable dataTable = CreateDataTable(request);

            using (esTransactionScope scope = new esTransactionScope())
            {
                using (SADataAdapter da = new SADataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                    SACommand cmd = null;

                    if (!request.IgnoreComputedColumns)
                    {
                        da.RowUpdated += new SARowUpdatedEventHandler(OnRowUpdated);
                    }

                    foreach (esEntitySavePacket packet in request.CollectionSavePacket)
                    {
                        if (packet.RowState != esDataRowState.Added && packet.RowState != esDataRowState.Modified) continue;

                        DataRow row = dataTable.NewRow();
                        dataTable.Rows.Add(row);

                        switch (packet.RowState)
                        {
                            case esDataRowState.Added:
                                cmd = da.InsertCommand = Shared.BuildDynamicInsertCommand(request, packet.ModifiedColumns);
                                SetModifiedValues(request, packet, row);
                                break;

                            case esDataRowState.Modified:
                                cmd = da.UpdateCommand = Shared.BuildDynamicUpdateCommand(request, packet.ModifiedColumns);
                                SetOriginalValues(request, packet, row, false);
                                SetModifiedValues(request, packet, row);
                                row.AcceptChanges();
                                row.SetModified();
                                break;
                        }

                        request.Properties["esDataRequest"] = request;
                        request.Properties["esEntityData"] = packet;
                        dataTable.ExtendedProperties["props"] = request.Properties;

                        DataRow[] singleRow = new DataRow[1];
                        singleRow[0] = row;

                        try
                        {
                            esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);

                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, packet, "SaveCollectionDynamic", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        da.Update(singleRow);
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                da.Update(singleRow);
                            }

                            if (row.HasErrors)
                            {
                                request.FireOnError(packet, row.RowError);
                            }
                        }
                        finally
                        {
                            esTransactionScope.DeEnlist(cmd);
                            dataTable.Rows.Clear();
                        }
                    }
                }

                scope.Complete();
            }

            return dataTable;
        }
示例#30
0
        private static DataTable SaveDynamicCollection_Deletes(esDataRequest request)
        {
            SACommand cmd = null;

            DataTable dataTable = CreateDataTable(request);

            using (esTransactionScope scope = new esTransactionScope())
            {
                using (SADataAdapter da = new SADataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                    try
                    {
                        da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                        cmd = da.DeleteCommand = Shared.BuildDynamicDeleteCommand(request, request.CollectionSavePacket[0]);
                        esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);

                        DataRow[] singleRow = new DataRow[1];

                        // Delete each record
                        foreach (esEntitySavePacket packet in request.CollectionSavePacket)
                        {
                            DataRow row = dataTable.NewRow();
                            dataTable.Rows.Add(row);

                            SetOriginalValues(request, packet, row, true);
                            row.AcceptChanges();
                            row.Delete();

                            singleRow[0] = row;

                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, packet, "SaveCollectionDynamic", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        da.Update(singleRow);
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                da.Update(singleRow);
                            }

                            if (row.HasErrors)
                            {
                                request.FireOnError(packet, row.RowError);
                            }

                            dataTable.Rows.Clear(); // ADO.NET won't let us reuse the same DataRow
                        }
                    }
                    finally
                    {
                        esTransactionScope.DeEnlist(cmd);
                    }
                }
                scope.Complete();
            }

            return request.Table;
        }
        public void ClientSideAliased()
        {
            int keyId = -1;
            CustomClientAliasedCollection coll = new CustomClientAliasedCollection();

            switch (coll.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.EffiProzProvider":
                    Assert.Ignore("Not implemented");
                    break;

                default:
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        // Setup
                        CustomClientAliased entity = new CustomClientAliased();

                        entity = new CustomClientAliased();
                        entity.FirstName = "Test";
                        entity.LastName = "One";

                        // Insert
                        entity.Save();
                        keyId = entity.AutoKey.Value;

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "One");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 1);

                        // Update
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "One");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 1);

                        DateTime modified = entity.DateModified.Value;
                        entity.LastName = "Two";
                        System.Threading.Thread.Sleep(4);
                        entity.Save();

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.Greater(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        // No Update
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);
                        DateTime added = entity.DateAddedAlias.Value;
                        modified = entity.DateModified.Value;

                        entity.Save();

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value, added);
                        Assert.AreEqual(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        // Clean up
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value, added);
                        Assert.AreEqual(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        entity.MarkAsDeleted();
                        entity.Save();

                        entity = new CustomClientAliased();
                        if (entity.LoadByPrimaryKey(keyId))
                        {
                            Assert.Fail("Not deleted");
                        }
                    }
                    break;
            }
        }
示例#32
0
        private static DataTable SaveStoredProcCollection(esDataRequest request)
        {
            bool needToInsert = false;
            bool needToUpdate = false;
            bool needToDelete = false;

            Dictionary<DataRow, esEntitySavePacket> rowMapping = null;

            if (request.ContinueUpdateOnError)
            {
                rowMapping = new Dictionary<DataRow, esEntitySavePacket>();
            }

            //================================================
            // Create the DataTable ...
            //================================================
            DataTable dataTable = CreateDataTable(request);

            foreach (esEntitySavePacket packet in request.CollectionSavePacket)
            {
                DataRow row = dataTable.NewRow();

                switch (request.EntitySavePacket.RowState)
                {
                    case esDataRowState.Added:
                        SetModifiedValues(request, packet, row);
                        dataTable.Rows.Add(row);
                        if (request.ContinueUpdateOnError) rowMapping[row] = packet;
                        break;

                    case esDataRowState.Modified:
                        SetOriginalValues(request, packet, row, false);
                        SetModifiedValues(request, packet, row);
                        dataTable.Rows.Add(row);
                        row.AcceptChanges();
                        row.SetModified();
                        if (request.ContinueUpdateOnError) rowMapping[row] = packet;
                        break;

                    case esDataRowState.Deleted:
                        SetOriginalValues(request, packet, row, true);
                        dataTable.Rows.Add(row);
                        row.AcceptChanges();
                        row.Delete();
                        if (request.ContinueUpdateOnError) rowMapping[row] = packet;
                        break;
                }
            }

            if (Shared.HasUpdates(dataTable.Rows, out needToInsert, out needToUpdate, out needToDelete))
            {
                using (SADataAdapter da = new SADataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError = request.ContinueUpdateOnError;

                    SACommand cmd = null;

                    if (needToInsert) da.InsertCommand = cmd = Shared.BuildStoredProcInsertCommand(request);
                    if (needToUpdate) da.UpdateCommand = cmd = Shared.BuildStoredProcUpdateCommand(request);
                    if (needToDelete) da.DeleteCommand = cmd = Shared.BuildStoredProcDeleteCommand(request);

                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        if (needToInsert) esTransactionScope.Enlist(da.InsertCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                        if (needToUpdate) esTransactionScope.Enlist(da.UpdateCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                        if (needToDelete) esTransactionScope.Enlist(da.DeleteCommand, request.ConnectionString, CreateIDbConnectionDelegate);

                        try
                        {
                            #region Profiling

                            if (sTraceHandler != null)
                            {
                                using (esTraceArguments esTrace = new esTraceArguments(request, cmd, "SaveCollectionStoredProcedure", System.Environment.StackTrace))
                                {
                                    try
                                    {
                                        da.Update(dataTable);
                                    }
                                    catch (Exception ex)
                                    {
                                        esTrace.Exception = ex.Message;
                                        throw;
                                    }
                                }
                            }
                            else

                            #endregion Profiling

                            {
                                da.Update(dataTable);
                            }
                        }
                        finally
                        {
                            if (needToInsert) esTransactionScope.DeEnlist(da.InsertCommand);
                            if (needToUpdate) esTransactionScope.DeEnlist(da.UpdateCommand);
                            if (needToDelete) esTransactionScope.DeEnlist(da.DeleteCommand);
                        }

                        scope.Complete();
                    }
                }

                if (request.ContinueUpdateOnError && dataTable.HasErrors)
                {
                    DataRow[] errors = dataTable.GetErrors();

                    foreach (DataRow rowWithError in errors)
                    {
                        request.FireOnError(rowMapping[rowWithError], rowWithError.RowError);
                    }
                }
            }

            return request.Table;
        }
		/// <summary>
		/// Used to Save the data to the database
		/// </summary>
		/// <returns>True if Successful</returns>
        public override bool Submit(ChangeSet changeSet)
        {
            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    bool success= base.Submit(changeSet);

                    if (success)
                    {
                        scope.Complete();
                    }

                    return success;
                }
            }
            catch (Exception ex)
            {
                if (!HandleError(ex))
                {
                    throw;
                }

                return true;
            }
        }
        public void WhereNotLikeTextEscaped()
        {
            int tempId = -1;

            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.MSAccessProvider":
                    Assert.Ignore("Not supported.");
                    break;
                default:
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            aggTest.LastName = "a 10% name";
                            aggTest.Save();
                            tempId = aggTest.Id.Value;

                            aggTestColl.Query
                                .Select()
                                .Where
                                (
                                    aggTestColl.Query.LastName.NotLike("%10!%%", '!')
                                );
                            Assert.IsTrue(aggTestColl.Query.Load());
                            Assert.AreEqual(24, aggTestColl.Count);
                        }
                    }
                    finally
                    {
                        // Clean up
                        aggTest = new AggregateTest();
                        if (aggTest.LoadByPrimaryKey(tempId))
                        {
                            aggTest.MarkAsDeleted();
                            aggTest.Save();
                        }
                    }
                    break;
            }
        }
        protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            DateTime TransDateMonth = DateTime.Now;
            try
            {
                TransDateMonth = (DateTime)(userControl.FindControl("dtpTransDate") as RadDatePicker).DbSelectedDate;
            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
            int transDateMonth = TransDateMonth.Month;
            //perubahan terakhir, autonumber mengikuti bulan transaksi, bukan bulan berjalan
            //string month = DateTime.Now.Month.ToString().Trim();
            string month = transDateMonth.ToString().Trim();
            string autonumber = "";
            if (month.Length == 1)
                month = ('0' + month).Trim();

            Trans Trans = new Trans();
            //Auto Number
            AutoNumberingQuery anQ = new AutoNumberingQuery();
            anQ.SelectAll();
            anQ.Where(anQ.KaMonth == month, anQ.KaYear == DateTime.Now.Year.ToString().Trim());
            AutoNumberingCollection anColl = new AutoNumberingCollection();

            anColl.Load(anQ);
            //KelAnggaranQuery kaQ = new KelAnggaranQuery();
            //kaQ.SelectAll();
            //kaQ.Where(kaQ.KaCode == (userControl.FindControl("cmbTransCODE") as RadComboBox).SelectedValue.Trim());
            //KelAnggaranCollection kaColl = new KelAnggaranCollection();

            //kaColl.Load(kaQ);            

            if (anColl.Count == 0)
            {
                AutoNumberingCollection anCollection = new AutoNumberingCollection();
                AutoNumbering aN = new AutoNumbering();
                aN = anCollection.AddNew();
                aN.KaYear = DateTime.Now.Year.ToString().Trim();
                aN.KaMonth = month;
                aN.LastNumber = 1;
                aN.PrefixNumber = "000";
                //AutoNumbering an = new AutoNumbering { KaYear = DateTime.Now.Year.ToString().Trim(), KaMonth = month, LastNumber = 1, PrefixNumber = "000" };
                autonumber = String.Format("{0}{1}{2}-0001", autonumber, DateTime.Now.Year.ToString().Trim(), month);
                //an.Save();

                try
                {
                    TransCollection transCollection = new TransCollection();
                    Trans = transCollection.AddNew();
                    //Trans.KaCode = (userControl.FindControl("cmbTransCODE") as RadComboBox).SelectedItem.Value;
                    Trans.KaCode = (userControl.FindControl("HiddenField1") as HiddenField).Value;
                    Trans.TransNumber = autonumber.ToUpper();
                    Trans.CekBgNumber = (userControl.FindControl("txtCek") as RadTextBox).Text;
                    //Trans.Amount = Convert.ToDecimal((userControl.FindControl("txtDebitAmount") as RadNumericTextBox).Value - (userControl.FindControl("txtCreditAmount") as RadNumericTextBox).Value);
                    Trans.DebitAmount = Convert.ToDecimal((userControl.FindControl("txtDebitAmount") as RadNumericTextBox).Value);
                    Trans.CreditAmount = Convert.ToDecimal((userControl.FindControl("txtCreditAmount") as RadNumericTextBox).Value);
                    Trans.Descript = (userControl.FindControl("txtDESC") as RadTextBox).Text;
                    Trans.KasId = (userControl.FindControl("cmbKasID") as RadComboBox).SelectedValue.ToUpper();
                    Trans.TransDate = (DateTime)(userControl.FindControl("dtpTransDate") as RadDatePicker).DbSelectedDate;
                    Trans.UserInsert = "toro";
                    Trans.TglInsert = DateTime.Now;
                    Trans.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                    Trans.Isverified = false;
                    Trans.IsClosed = false;

                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        anCollection.Save();
                        transCollection.Save();
                        scope.Complete();
                    }  
                }
                catch (Exception ex)
                {
                    string es = ex.Message;
                }
                finally
                {
                    RadGrid1.Rebind();
                }
            }
            else
                foreach (AutoNumbering aa in anColl)
                {
                    string i = (aa.LastNumber + 1).ToString().Trim();
                    if (i.Length == 1)
                        autonumber = String.Format("{0}{1}{2}-000{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 2)
                        autonumber = String.Format("{0}{1}{2}-00{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 3)
                        autonumber = String.Format("{0}{1}{2}-0{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    if (i.Length == 4)
                        autonumber = String.Format("{0}{1}{2}-{3}", autonumber, aa.KaYear, aa.KaMonth, i);
                    AutoNumbering anb = new AutoNumbering();
                    AutoNumberingCollection anCollection = new AutoNumberingCollection();
                    anb = anCollection.AddNew();
                    if (anb.LoadByPrimaryKey((long)aa.Id))
                    {
                        anb.LastNumber = aa.LastNumber + 1;                        

                        try
                        {
                            TransCollection transCollection = new TransCollection();
                            Trans = transCollection.AddNew();                            
                            Trans.KaCode = (userControl.FindControl("HiddenField1") as HiddenField).Value;
                            Trans.TransNumber = autonumber.ToUpper();
                            Trans.CekBgNumber = (userControl.FindControl("txtCek") as RadTextBox).Text;                            
                            Trans.DebitAmount = Convert.ToDecimal((userControl.FindControl("txtDebitAmount") as RadNumericTextBox).Value);
                            Trans.CreditAmount = Convert.ToDecimal((userControl.FindControl("txtCreditAmount") as RadNumericTextBox).Value);
                            Trans.Descript = (userControl.FindControl("txtDESC") as RadTextBox).Text;
                            Trans.KasId = (userControl.FindControl("cmbKasID") as RadComboBox).SelectedValue.ToUpper();
                            Trans.TransDate = (DateTime)(userControl.FindControl("dtpTransDate") as RadDatePicker).DbSelectedDate;
                            Trans.UserInsert = "toro";
                            Trans.TglInsert = DateTime.Now;
                            Trans.PeriodId = (Int32)HttpContext.Current.Session["_periodeId"];
                            Trans.Isverified = false;
                            Trans.IsClosed = false;

                            anb.LastNumber = aa.LastNumber + 1;

                            using (esTransactionScope scope = new esTransactionScope())
                            {                                
                                transCollection.Save();
                                scope.Complete();
                            }
                            anb.Save();                            
                        }
                        catch (Exception ex)
                        {
                            string es = ex.Message;
                        }
                        finally
                        {
                            RadGrid1.Rebind();
                        }
                    }
                }

        }
		public void GuidDynamicQuery()
		{
            GuidTestCollection dataTestColl = new GuidTestCollection();
            dataTestColl.es.Connection.Name = "GuidTest";
            GuidTest dataTest = new GuidTest();
            dataTest.es.Connection.Name = "GuidTest";

            switch (dataTest.es.Connection.ProviderMetadataKey)
            {
                case "esSqlCe":
                case "esSqlCe4":
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        dataTest = new GuidTest();
                        dataTest.es.Connection.Name = "GuidTest";
                        dataTest.GuidKey = Guid.NewGuid();
                        dataTest.Save();
                        Guid tempKey = dataTest.GuidKey.Value;

                        dataTestColl = new GuidTestCollection();
                        dataTestColl.es.Connection.Name = "GuidTest";
                        dataTestColl.Query.Where(dataTestColl.Query.GuidKey == tempKey);
                        dataTestColl.Query.Load();
                        Assert.AreEqual(1, dataTestColl.Count);

                        dataTest = new GuidTest();
                        dataTest.es.Connection.Name = "GuidTest";
                        Assert.IsTrue(dataTest.LoadByPrimaryKey(tempKey));
                        dataTest.MarkAsDeleted();
                        dataTest.Save();
                    }
                    break;

                default:
                    Assert.Ignore("SqlCe only");
                    break;
            }
		}
        public void ConcurrencyOnUpdate()
        {
            ConcurrencyTestCollection collection = new ConcurrencyTestCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlServerCeProvider":
                case "EntitySpaces.SqlServerCe4Provider":
                    Assert.Ignore("Not implemented for SqlCe");
                    break;

                default:
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            // Setup
                            ConcurrencyTest entity = new ConcurrencyTest();
                            if (entity.LoadByPrimaryKey("abc"))
                            {
                                entity.MarkAsDeleted();
                                entity.Save();
                            }

                            entity = new ConcurrencyTest();
                            entity.Id = "abc";
                            entity.Name = "Test 1";
                            entity.Save();

                            // Test
                            entity = new ConcurrencyTest();
                            entity.LoadByPrimaryKey("abc");
                            Assert.AreEqual(1, entity.ConcurrencyCheck, "Check 1");
                            entity.Name = "Test 2";
                            entity.Save();

                            entity = new ConcurrencyTest();
                            entity.LoadByPrimaryKey("abc");
                            Assert.AreEqual(2, entity.ConcurrencyCheck, "Check 2");
                            entity.Name = "Test 3";
                            entity.Save();

                            entity = new ConcurrencyTest();
                            entity.LoadByPrimaryKey("abc");
                            Assert.AreEqual(3, entity.ConcurrencyCheck, "Check 3");
                            entity.Name = "Test 4";

                            ConcurrencyTest entity2 = new ConcurrencyTest();
                            entity2.LoadByPrimaryKey("abc");
                            entity2.Name = "Collision";

                            entity.Save();
                            entity2.Save();
                            Assert.Fail("Concurrency Exception not thrown.");
                        }
                    }
                    catch (EntitySpaces.Interfaces.esConcurrencyException cex)
                    {
                        switch (collection.es.Connection.ProviderSignature.DataProviderName)
                        {
                            case "EntitySpaces.MSAccessProvider":
                            case "EntitySpaces.MySqlClientProvider":
                            case "EntitySpaces.SQLiteProvider":
                            case "EntitySpaces.SqlServerCeProvider":
                            case "EntitySpaces.SybaseSqlAnywhereProvider":
                            case "EntitySpaces.VistaDBProvider":
                            case "EntitySpaces.VistaDB4Provider":
                                Assert.AreEqual("Error in", cex.Message.Substring(0, 8));
                                break;

                            case "EntitySpaces.OracleClientProvider":
                                Assert.AreEqual("ORA-20101", cex.Message.Substring(0, 9));
                                break;

                            default:
                                Assert.AreEqual("Update failed", cex.Message.Substring(0, 13));
                                break;
                        }
                    }
                    finally
                    {
                        // Clean up
                        ConcurrencyTest entity = new ConcurrencyTest();
                        if (entity.LoadByPrimaryKey("abc"))
                        {
                            entity.MarkAsDeleted();
                            entity.Save();
                        }
                    }
                    break;
            }
        }