예제 #1
0
        public void Does_support_multiple_self_joins_with_nullable_ints()
        {
            using (var db = OpenDbConnection())
            {
                db.DropTable <ParentSelfRef>();
                db.DropTable <ChildSelfRef>();

                db.CreateTable <ChildSelfRef>();
                db.CreateTable <ParentSelfRef>();

                var row = new ParentSelfRef
                {
                    Child1 = new ChildSelfRef
                    {
                        Name = "Child 1"
                    },
                    Child2 = new ChildSelfRef
                    {
                        Name = "Child 2"
                    },
                };

                db.Save(row, references: true);

                row.PrintDump();

                Assert.That(row.Id, Is.EqualTo(1));
                Assert.That(row.Child1Id, Is.EqualTo(1));
                Assert.That(row.Child1.Id, Is.EqualTo(1));
                Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
                Assert.That(row.Child2Id, Is.EqualTo(2));
                Assert.That(row.Child2.Id, Is.EqualTo(2));
                Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));

                row = db.LoadSingleById <ParentSelfRef>(row.Id);

                Assert.That(row.Id, Is.EqualTo(1));
                Assert.That(row.Child1Id, Is.EqualTo(1));
                Assert.That(row.Child1.Id, Is.EqualTo(1));
                Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
                Assert.That(row.Child2Id, Is.EqualTo(2));
                Assert.That(row.Child2.Id, Is.EqualTo(2));
                Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));
            }
        }
        public void Does_support_multiple_self_joins_with_nullable_ints()
        {
            using (var db = OpenDbConnection())
            {
                db.DropTable<ParentSelfRef>();
                db.DropTable<ChildSelfRef>();

                db.CreateTable<ChildSelfRef>();
                db.CreateTable<ParentSelfRef>();

                var row = new ParentSelfRef
                {
                    Child1 = new ChildSelfRef
                    {
                        Name = "Child 1"
                    },
                    Child2 = new ChildSelfRef
                    {
                        Name = "Child 2"
                    },
                };

                db.Save(row, references: true);

                row.PrintDump();

                Assert.That(row.Id, Is.EqualTo(1));
                Assert.That(row.Child1Id, Is.EqualTo(1));
                Assert.That(row.Child1.Id, Is.EqualTo(1));
                Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
                Assert.That(row.Child2Id, Is.EqualTo(2));
                Assert.That(row.Child2.Id, Is.EqualTo(2));
                Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));

                row = db.LoadSingleById<ParentSelfRef>(row.Id);

                Assert.That(row.Id, Is.EqualTo(1));
                Assert.That(row.Child1Id, Is.EqualTo(1));
                Assert.That(row.Child1.Id, Is.EqualTo(1));
                Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
                Assert.That(row.Child2Id, Is.EqualTo(2));
                Assert.That(row.Child2.Id, Is.EqualTo(2));
                Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));
            }
        }