Esempio n. 1
0
        public void Recursive()
        {
            using (var conn = OpenConnection())
            {
                conn.ExecuteNonQuery("CREATE TYPE pg_temp.composite_contained AS (x int, some_text text)");
                conn.ExecuteNonQuery("CREATE TYPE pg_temp.composite_container AS (a int, contained composite_contained)");
                conn.ReloadTypes();
                // Registration in inverse dependency order should work
                conn.MapComposite <SomeCompositeContainer>("composite_container");
                conn.MapComposite <SomeComposite>("composite_contained");

                var expected = new SomeCompositeContainer {
                    a         = 4,
                    Contained = new SomeComposite {
                        x = 8, SomeText = "foo"
                    }
                };

                using (var cmd = new NpgsqlCommand("SELECT @p::composite_container", conn))
                {
                    cmd.Parameters.AddWithValue("p", expected);
                    using (var reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        var actual = reader.GetFieldValue <SomeCompositeContainer>(0);
                        Assert.That(actual.a, Is.EqualTo(4));
                        Assert.That(actual.Contained.x, Is.EqualTo(8));
                        Assert.That(actual.Contained.SomeText, Is.EqualTo("foo"));
                    }
                }
            }
        }
Esempio n. 2
0
        public void Recursive()
        {
            var csb = new NpgsqlConnectionStringBuilder(ConnectionString)
            {
                ApplicationName = nameof(Recursive),
                Pooling         = false
            };

            using var conn = OpenConnection(csb);
            conn.ExecuteNonQuery("CREATE TYPE pg_temp.composite_contained AS (x int, some_text text)");
            conn.ExecuteNonQuery("CREATE TYPE pg_temp.composite_container AS (a int, contained composite_contained)");
            conn.ReloadTypes();
            // Registration in inverse dependency order should work
            conn.TypeMapper.MapComposite <SomeCompositeContainer>("composite_container");
            conn.TypeMapper.MapComposite <SomeComposite>("composite_contained");

            var expected = new SomeCompositeContainer {
                A         = 4,
                Contained = new SomeComposite {
                    X = 8, SomeText = "foo"
                }
            };

            using var cmd = new NpgsqlCommand("SELECT @p::composite_container", conn);
            cmd.Parameters.AddWithValue("p", expected);
            using var reader = cmd.ExecuteReader();
            reader.Read();
            var actual = reader.GetFieldValue <SomeCompositeContainer>(0);

            Assert.That(actual.A, Is.EqualTo(4));
            Assert.That(actual.Contained.X, Is.EqualTo(8));
            Assert.That(actual.Contained.SomeText, Is.EqualTo("foo"));
        }