Пример #1
0
 public void GetCompanyById_Sql()
 {
     var     operation = new DbCommandOperation <Company, GetCompanyById_Sql>("Local");
     Company _result   = operation.ExecuteSingleReader(new GetCompanyById_Sql()
     {
         Id = 1
     });
 }
        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);
        }
Пример #3
0
        public void TestDBStringArrayParameter2()
        {
            var operation  = new DbCommandOperation <Company, GetCompanies2>("Local");
            var parameters = new GetCompanies2()
            {
                Id = new int[] { 1, 3, 6, 9 }
            };
            IEnumerable <Company> _result = operation.ExecuteReader(parameters);

            var _resultMaterialized = _result.ToList();
        }
Пример #4
0
        public void TestCreateNewDataProvider()
        {
            var operation = new DbCommandOperation <Company, GetCompanyAll>("LocalCustom");

            operation.PreExecute += Operation_PreExecute;
            IEnumerable <Company> _result = operation.ExecuteReader(new GetCompanyAll()
            {
            });

            var _resultMaterialized = _result.ToList();
        }
        public void GetCompanyById()
        {
            // NOTE:
            // Each construction of DbCommandOperation means it does initializion on first call.
            // when using multiple times it's best to set the declaration on class level instead of method level.

            var     operation = new DbCommandOperation <Company, GetCompanyById>("Local");
            Company _result   = operation.ExecuteSingleReader(new GetCompanyById()
            {
                Id = 1
            });
        }
Пример #6
0
        public void SelectAll()
        {
            var operation = new DbCommandOperation <Company, GetCompanyAll>("Local");
            IEnumerable <Company> _result = operation.ExecuteReader(new GetCompanyAll()
            {
            });
            var _resultMaterialized = _result.ToList();

            var operation2 = new DbCommandOperation <Company, GetCompanyAll>("Local");
            IEnumerable <Company> _result2 = operation2.ExecuteReader(new GetCompanyAll()
            {
            });
            var _resultMaterialized2 = _result2.ToList();
        }
        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;
            }
        }
Пример #8
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);
        }
        public void SelectAll()
        {
            var operation = new DbCommandOperation <Company, GetCompanyAll>("Local");
            IEnumerable <Company> _result = operation.ExecuteReader(new GetCompanyAll()
            {
            });

            StopWatch _watch = new StopWatch();

            _watch.Start();

            var _resultMaterialized = _result.ToList();

            _watch.Stop();

            Console.WriteLine(_watch.Duration);
        }
Пример #10
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();
            }
        }