public void Can_save_complex_types_as_JSON()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable<ModelWithJsonType>();

                db.GetLastSql().Print();

                var row = new ModelWithJsonType
                {
                    Id = 1,
                    ComplexTypeJson = new ComplexType
                    {
                        Id = 2, SubType = new SubType { Name = "SubType2" }
                    },
                    //ComplexTypeJsonb = new ComplexType
                    //{
                    //    Id = 3, SubType = new SubType { Name = "SubType3" }
                    //},
                };

                db.Insert(row);

                var result = db.Select<ModelWithJsonType>(
                    "complex_type_json->'sub_type'->>'name' = 'SubType2'");

                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result[0].Id, Is.EqualTo(2));
                Assert.That(result[0].ComplexTypeJson.SubType, Is.EqualTo("SubType2"));
            }
        }
Example #2
0
        public void Can_save_complex_types_as_JSON()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <ModelWithJsonType>();

                db.GetLastSql().Print();

                var row = new ModelWithJsonType
                {
                    Id = 1,
                    ComplexTypeJson = new ComplexType
                    {
                        Id = 2, SubType = new SubType {
                            Name = "SubType2"
                        }
                    },
                    //ComplexTypeJsonb = new ComplexType
                    //{
                    //    Id = 3, SubType = new SubType { Name = "SubType3" }
                    //},
                };

                db.Insert(row);

                var result = db.Select <ModelWithJsonType>(
                    "complex_type_json->'sub_type'->>'name' = 'SubType2'");

                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result[0].Id, Is.EqualTo(2));
                Assert.That(result[0].ComplexTypeJson.SubType, Is.EqualTo("SubType2"));
            }
        }