public void InsertBinary()
        {
            var operation = new DbCommandOperation <InsertPhoto>("Local");
            IEnumerable <InsertPhoto> commands = GetFiles().Select(p => new InsertPhoto()
            {
                Photo = File.ReadAllBytes(p.FullName), Name = p.Name
            });

            operation.ExecuteNonQuery(commands);
        }
        public void TestInsertRandomData()
        {
            var operation = new DbCommandOperation <InsertCompanyRandom>("Local");

            InsertCompanyRandom parameters = new InsertCompanyRandom()
            {
            };

            for (int ii = 0; ii < 50; ii++)
            {
                operation.ExecuteNonQuery(parameters);
                int newId = parameters.Id;
            }
        }
Пример #3
0
        public void InsertNull()
        {
            var insert = new InsertCompanyBySqlStatement()
            {
                Name        = "First Company",
                Adress      = "New Adres",
                Country     = "NL",
                HouseNumber = "12",
                CompanyType = CompanyType.BV,
                Text        = null,
                ZipCode     = "ABCD12"
            };
            var operationInsert = new DbCommandOperation <InsertCompanyBySqlStatement>("Local");

            operationInsert.ExecuteNonQuery(insert);
        }
Пример #4
0
        public void InsertCompany2()
        {
            var operation = new DbCommandOperation <InsertCompanyBySqlStatement>("Local");

            InsertCompanyBySqlStatement parameters = new InsertCompanyBySqlStatement()
            {
                Adress      = "",
                Country     = "NLD",
                HouseNumber = "180",
                Name        = "A Company Name",
                ZipCode     = "4624JC",
                CompanyType = CompanyType.NV,
                Text        = "My Name"
            };

            operation.ExecuteNonQuery(parameters);

            int newId = parameters.Id;
        }
        public void InsertCompanyTransactional()
        {
            // Delete all companies outside Transaction.
            var deleteoperation = new DbCommandOperation <DeleteAllCompanies>("Local");

            deleteoperation.ExecuteNonQuery();

            var operation1 = new DbCommandOperation <InsertCompanyByProcedure>("Local");
            var operation2 = new DbCommandOperation <InsertCompanyBySqlStatement>("Local");

            using (DbConnection connection = operation1.CreateConnection())
            {
                // operation1.CreateConnection() : operation1 determines the connection to use.
                // the result is the same as  operation2.CreateConnection(), they both create a ConnectionObject from Config "Local"

                connection.Open();
                using (DbTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        InsertCompanyByProcedure insert1 = new InsertCompanyByProcedure()
                        {
                            Adress      = "",
                            Country     = "NLD",
                            HouseNumber = "",
                            Name        = "A Company Name",
                            ZipCode     = "4624JC",
                            CompanyType = CompanyType.NV,
                            Text        = "Guido Kleijer2"
                        };

                        operation1.ExecuteNonQuery(connection, transaction, insert1);

                        int newId = insert1.Id;

                        // Too large ZipCode
                        InsertCompanyBySqlStatement insert2 = new InsertCompanyBySqlStatement()
                        {
                            Adress      = "",
                            Country     = "NLD",
                            HouseNumber = "",
                            Name        = "A Company Name ",
                            ZipCode     = "4624JC TO LONG AAAAAAAAAAAbbbbbbbbbbbAAAAAAAAA TO LONG",
                            CompanyType = CompanyType.NV,
                            Text        = "Guido Kleijer"
                        };

                        operation2.ExecuteNonQuery(connection, transaction, insert2);

                        int newId2 = insert2.Id;

                        transaction.Commit();
                    }
                    catch (Exception exception)
                    {
                        transaction.Rollback();
                    }
                }
                connection.Close();
            }
        }