Beispiel #1
0
        public void Z_Test_0071()
        {
            // Title2: Map_NotMapped

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                DapperPlusManager.Entity <EntitySimple_Mapper>("0effcb58-a856-4714-afc9-5dafcd57c43d").Map(x => x.Single1).Map(x => x.Single2); cn.BulkInsert("0effcb58-a856-4714-afc9-5dafcd57c43d", single);
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
				SELECT TOP 1
						[Single1] ,
						[Single2] ,
						[Many1] ,
						[Many2] ,
						[Many3] ,
						[Many4] ,
						[Single1_Destination] ,
						[Single2_Destination] ,
						[Many1_Destination] ,
						[Many2_Destination] ,
						[Many3_Destination] ,
						[Many4_Destination] "                         +
                                          "FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_Mapper]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
            Assert.AreEqual(single.Single1, single1);
            Assert.AreEqual(single.Single2, single2);
            Assert.AreEqual(0, many1);
            Assert.AreEqual(0, many2);
            Assert.AreEqual(0, many3);
            Assert.AreEqual(0, many4);
            Assert.AreEqual(0, single1_Destination);
            Assert.AreEqual(0, single2_Destination);
            Assert.AreEqual(0, many1_Destination);
            Assert.AreEqual(0, many2_Destination);
            Assert.AreEqual(0, many3_Destination);
            Assert.AreEqual(0, many4_Destination);
            Assert.AreEqual(single.Single1, single.Single1);
            Assert.AreEqual(single.Single2, single.Single2);
            Assert.AreEqual(single.Many1, single.Many1);
            Assert.AreEqual(single.Many2, single.Many2);
            Assert.AreEqual(single.Many3, single.Many3);
            Assert.AreEqual(single.Many4, single.Many4);
        }
Beispiel #2
0
        public void Z_Test_0096()
        {
            Helper.CleanDatabase();

            var single1 = new SingleMany {
                ColumnInt = 1
            };
            var single2 = new SingleMany {
                ColumnInt = 8
            };
            var single3 = new SingleMany {
                ColumnInt = 64
            };

            var many1 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 512
                }, new SingleMany {
                    ColumnInt = 1024
                }, new SingleMany {
                    ColumnInt = 2048
                }
            };
            var many2 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 4096
                }, new SingleMany {
                    ColumnInt = 8192
                }, new SingleMany {
                    ColumnInt = 16384
                }
            };
            var many3 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 32768
                }, new SingleMany {
                    ColumnInt = 65536
                }, new SingleMany {
                    ColumnInt = 131072
                }
            };

            Helper.LinkSingleMany(single1, single2, single3, many1, many2, many3);
            Helper.InsertFromMetas("BulkInsertAll;UpdateValueAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3);
            Helper.UpdateFromMetas("BulkInsertAll;UpdateValueAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3);

            // GET count before
            int columnInt_before           = 0;
            int columnUpdateInt_before     = 0;
            int columnInt_Key_before       = 0;
            int columnUpdateInt_Key_before = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)";
                    columnInt_before    = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText    = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)";
                    columnUpdateInt_before = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText  = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)";
                    columnInt_Key_before = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText        = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)";
                    columnUpdateInt_Key_before = Convert.ToInt32(command.ExecuteScalar());
                }
            }

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                cn.BulkUpdate("key", many1, x => x.Many2, x => x.Single2, x => x.Single3);
            }

            // GET count
            int columnInt           = 0;
            int columnUpdateInt     = 0;
            int columnInt_Key       = 0;
            int columnUpdateInt_Key = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)";
                    columnInt           = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)";
                    columnUpdateInt     = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)";
                    columnInt_Key       = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)";
                    columnUpdateInt_Key = Convert.ToInt32(command.ExecuteScalar());
                }
            }

            // Test
            Assert.AreEqual(columnInt_before, columnInt);
            Assert.AreEqual(columnUpdateInt_before, columnUpdateInt);
            Assert.AreEqual(columnInt_Key_before, columnInt_Key);
            Assert.AreEqual(many1.Sum(x => x.ColumnInt) + many1.Sum(x => x.Many2.Sum(y => y.ColumnInt)) + many1.Sum(x => x.Single2.ColumnInt) + many1.Sum(x => x.Single3.ColumnInt), columnUpdateInt_Key);
        }
Beispiel #3
0
        public void Z_Test_0010()
        {
            // Title2: MapSingleDestination_MapManyDestination

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                DapperPlusManager.Entity <EntitySimple_Mapper>("358f4237-5635-453b-b526-5cf6cf38d6a9").Map(x => x.Single1, "Single1_Destination").Map(x => new { Many3_Destination = x.Many3, Many4_Destination = x.Many4 }); cn.BulkInsert("358f4237-5635-453b-b526-5cf6cf38d6a9", single);
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
SELECT TOP 1
        [Single1] ,
        [Single2] ,
        [Many1] ,
        [Many2] ,
        [Many3] ,
        [Many4] ,
        [Single1_Destination] ,
        [Single2_Destination] ,
        [Many1_Destination] ,
        [Many2_Destination] ,
        [Many3_Destination] ,
        [Many4_Destination]
FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_Mapper]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
            Assert.AreEqual(0, single1);
            Assert.AreEqual(0, single2);
            Assert.AreEqual(0, many1);
            Assert.AreEqual(0, many2);
            Assert.AreEqual(0, many3);
            Assert.AreEqual(0, many4);

            Assert.AreEqual(singleBefore.Single1, single1_Destination);
            Assert.AreEqual(0, single2_Destination);
            Assert.AreEqual(0, many1_Destination);
            Assert.AreEqual(0, many2_Destination);
            Assert.AreEqual(singleBefore.Many3, many3_Destination);
            Assert.AreEqual(singleBefore.Many4, many4_Destination);

            Assert.AreEqual(singleBefore.Single1, single.Single1);
            Assert.AreEqual(singleBefore.Single2, single.Single2);
            Assert.AreEqual(singleBefore.Many1, single.Many1);
            Assert.AreEqual(singleBefore.Many2, single.Many2);
            Assert.AreEqual(singleBefore.Many3, single.Many3);
            Assert.AreEqual(singleBefore.Many4, single.Many4);
        }
Beispiel #4
0
        public void Z_Test_0027()
        {
            // Title2: IdentitySingle

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                DapperPlusManager.Entity <EntitySimple_Mapper>("7924b882-209e-42b8-a008-8f0d4a16b4d3").Table("EntitySimple_TriggerOutput").Identity(x => x.Single1); cn.BulkInsert("7924b882-209e-42b8-a008-8f0d4a16b4d3", single);
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
				SELECT TOP 1
						[Single1] ,
						[Single2] ,
						[Many1] ,
						[Many2] ,
						[Many3] ,
						[Many4] ,
						[Single1_Destination] ,
						[Single2_Destination] ,
						[Many1_Destination] ,
						[Many2_Destination] ,
						[Many3_Destination] ,
						[Many4_Destination] "                         +
                                          "FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_TriggerOutput]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
            Assert.AreEqual(-singleBefore.Single1, single.Single1);
            Assert.AreEqual(singleBefore.Single2, single.Single2);
            Assert.AreEqual(singleBefore.Many1, single.Many1);
            Assert.AreEqual(singleBefore.Many2, single.Many2);
            Assert.AreEqual(singleBefore.Many3, single.Many3);
            Assert.AreEqual(singleBefore.Many4, single.Many4);
        }
Beispiel #5
0
        public async Task Z_Test_0097()
        {
            Helper.CleanDatabase();

            var single1 = new SingleMany {
                ColumnInt = 1
            };
            var single2 = new SingleMany {
                ColumnInt = 8
            };
            var single3 = new SingleMany {
                ColumnInt = 64
            };

            var many1 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 512
                }, new SingleMany {
                    ColumnInt = 1024
                }, new SingleMany {
                    ColumnInt = 2048
                }
            };
            var many2 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 4096
                }, new SingleMany {
                    ColumnInt = 8192
                }, new SingleMany {
                    ColumnInt = 16384
                }
            };
            var many3 = new List <SingleMany> {
                new SingleMany {
                    ColumnInt = 32768
                }, new SingleMany {
                    ColumnInt = 65536
                }, new SingleMany {
                    ColumnInt = 131072
                }
            };

            Helper.LinkSingleMany(single1, single2, single3, many1, many2, many3);
            Helper.InsertFromMetas("BulkInsertAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3);
            Helper.UpdateFromMetas("BulkInsertAll".Split(';').ToList(), single1, single2, single3, many1, many2, many3);

            // GET count before
            int columnInt_before           = 0;
            int columnUpdateInt_before     = 0;
            int columnInt_Key_before       = 0;
            int columnUpdateInt_Key_before = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)";
                    columnInt_before    = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText    = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)";
                    columnUpdateInt_before = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText  = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)";
                    columnInt_Key_before = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText        = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)";
                    columnUpdateInt_Key_before = Convert.ToInt32(command.ExecuteScalar());
                }
            }

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                await cn.BulkActionAsync(action => action.BulkDelete(single1));
            }

            // GET count
            int columnInt           = 0;
            int columnUpdateInt     = 0;
            int columnInt_Key       = 0;
            int columnUpdateInt_Key = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany), 0)";
                    columnInt           = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany), 0)";
                    columnUpdateInt     = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnInt) FROM SingleMany_Key), 0)";
                    columnInt_Key       = Convert.ToInt32(command.ExecuteScalar());

                    command.CommandText = "SELECT ISNULL((SELECT SUM(ColumnUpdateInt) FROM SingleMany_Key), 0)";
                    columnUpdateInt_Key = Convert.ToInt32(command.ExecuteScalar());
                }
            }

            // Test
            Assert.AreEqual(columnInt_before - single1.ColumnInt, columnInt);
            Assert.AreEqual(columnUpdateInt_before, columnUpdateInt);
            Assert.AreEqual(columnInt_Key_before, columnInt_Key);
            Assert.AreEqual(columnUpdateInt_Key_before, columnUpdateInt_Key);
        }
Beispiel #6
0
        public void Z_Test_0023()
        {
            // Title2: IgnoreSingle_IgnoreMany

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                DapperPlusManager.Entity <EntitySimple_Mapper>("6df57227-46a5-478e-a78d-571747454b93").Ignore(x => x.Single1).Ignore(x => new { x.Many3, x.Many4 }); cn.BulkInsert("6df57227-46a5-478e-a78d-571747454b93", single);
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
SELECT TOP 1
        [Single1] ,
        [Single2] ,
        [Many1] ,
        [Many2] ,
        [Many3] ,
        [Many4] ,
        [Single1_Destination] ,
        [Single2_Destination] ,
        [Many1_Destination] ,
        [Many2_Destination] ,
        [Many3_Destination] ,
        [Many4_Destination]
FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_Mapper]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
            Assert.AreEqual(0, single1);
            Assert.AreEqual(singleBefore.Single2, single2);
            Assert.AreEqual(singleBefore.Many1, many1);
            Assert.AreEqual(singleBefore.Many2, many2);
            Assert.AreEqual(0, many3);
            Assert.AreEqual(0, many4);

            Assert.AreEqual(0, single1_Destination);
            Assert.AreEqual(0, single2_Destination);
            Assert.AreEqual(0, many1_Destination);
            Assert.AreEqual(0, many2_Destination);
            Assert.AreEqual(0, many3_Destination);
            Assert.AreEqual(0, many4_Destination);

            Assert.AreEqual(singleBefore.Single1, single.Single1);
            Assert.AreEqual(singleBefore.Single2, single.Single2);
            Assert.AreEqual(singleBefore.Many1, single.Many1);
            Assert.AreEqual(singleBefore.Many2, single.Many2);
            Assert.AreEqual(singleBefore.Many3, single.Many3);
            Assert.AreEqual(singleBefore.Many4, single.Many4);
        }
Beispiel #7
0
        public void Z_Test_0055()
        {
            // Title2: OutputSingleDestination_OutputMany

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                DapperPlusManager.Entity <EntitySimple_Mapper>("ef59dd1f-ab17-47b7-b24d-9c02644a3b5a").Table("EntitySimple_TriggerOutput").Output(x => x.Single1, "Single1_Destination").Output(x => new { x.Many3, x.Many4 }); cn.BulkInsert("ef59dd1f-ab17-47b7-b24d-9c02644a3b5a", single);
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
				SELECT TOP 1
						[Single1] ,
						[Single2] ,
						[Many1] ,
						[Many2] ,
						[Many3] ,
						[Many4] ,
						[Single1_Destination] ,
						[Single2_Destination] ,
						[Many1_Destination] ,
						[Many2_Destination] ,
						[Many3_Destination] ,
						[Many4_Destination] "                         +
                                          "FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_TriggerOutput]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
            Assert.AreEqual(-singleBefore.Single1 * 100, single.Single1);
            Assert.AreEqual(singleBefore.Single2, single.Single2);
            Assert.AreEqual(singleBefore.Many1, single.Many1);
            Assert.AreEqual(singleBefore.Many2, single.Many2);
            Assert.AreEqual(-singleBefore.Many3, single.Many3);
            Assert.AreEqual(-singleBefore.Many4, single.Many4);
        }
Beispiel #8
0
        public void Z_Test_0070()
        {
            // Title2: MapDestination_MappedDestination

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                Exception ex = null;
                try
                {
                    DapperPlusManager.Entity <EntitySimple_Mapper>("b6dc0ae6-0cb2-417c-ab4b-eeb24b75de7c").Map(x => x.Single1, "Single1").Map(x => x.Single1, "Single1"); cn.BulkInsert("b6dc0ae6-0cb2-417c-ab4b-eeb24b75de7c", single);
                }
                catch (Exception exception)
                {
                    ex = exception;
                }
                Assert.IsNotNull(ex);
                Assert.AreEqual("One of your column have a destination mapped more then once. See the inner exception for details.", ex.Message);
                return;
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
				SELECT TOP 1
						[Single1] ,
						[Single2] ,
						[Many1] ,
						[Many2] ,
						[Many3] ,
						[Many4] ,
						[Single1_Destination] ,
						[Single2_Destination] ,
						[Many1_Destination] ,
						[Many2_Destination] ,
						[Many3_Destination] ,
						[Many4_Destination] "                         +
                                          "FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_TriggerOutput]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
        }
Beispiel #9
0
        public void Z_Test_0077()
        {
            // Title2: Output_NotMapped

            Helper.CleanDatabase();

            var singleBefore = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };
            var single = new EntitySimple_Mapper {
                Single1 = 1, Single2 = 2, Many1 = 10, Many2 = 20, Many3 = 30, Many4 = 40
            };

            using (var cn = Helper.GetConnection())
            {
                cn.Open();

                // PreTest

                // Action
                Exception ex = null;
                try
                {
                    DapperPlusManager.Entity <EntitySimple_Mapper>("42190a57-70b7-42ae-83b6-671cf622c3e2").Map(x => x.Single1).Output(x => x.Single2); cn.BulkInsert("42190a57-70b7-42ae-83b6-671cf622c3e2", single);
                }
                catch (Exception exception)
                {
                    ex = exception;
                }
                Assert.IsNotNull(ex);
                Assert.AreEqual("Specified cast is not valid.", ex.Message);
                return;
            }

            // GET count
            int single1 = 0;
            int single2 = 0;
            int many1   = 0;
            int many2   = 0;
            int many3   = 0;
            int many4   = 0;

            int single1_Destination = 0;
            int single2_Destination = 0;
            int many1_Destination   = 0;
            int many2_Destination   = 0;
            int many3_Destination   = 0;
            int many4_Destination   = 0;

            using (var connection = Helper.GetConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = @"
				SELECT TOP 1
						[Single1] ,
						[Single2] ,
						[Many1] ,
						[Many2] ,
						[Many3] ,
						[Many4] ,
						[Single1_Destination] ,
						[Single2_Destination] ,
						[Many1_Destination] ,
						[Many2_Destination] ,
						[Many3_Destination] ,
						[Many4_Destination] "                         +
                                          "FROM    [Z.Dapper.Plus].[dbo].[EntitySimple_TriggerOutput]";

                    using (var reader = command.ExecuteReader())
                    {
                        reader.Read();
                        single1 = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        single2 = reader.IsDBNull(1) ? 0 : reader.GetInt32(1);
                        many1   = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
                        many2   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                        many3   = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                        many4   = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                        single1_Destination = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                        single2_Destination = reader.IsDBNull(7) ? 0 : reader.GetInt32(7);
                        many1_Destination   = reader.IsDBNull(8) ? 0 : reader.GetInt32(8);
                        many2_Destination   = reader.IsDBNull(9) ? 0 : reader.GetInt32(9);
                        many3_Destination   = reader.IsDBNull(10) ? 0 : reader.GetInt32(10);
                        many4_Destination   = reader.IsDBNull(11) ? 0 : reader.GetInt32(11);
                    }
                }
            }

            // Test
        }