예제 #1
0
        public void Select_Tuple_FromRightJoin_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);
            var otherMany = new TestManyPoco {
                Toto = "OtherToto", Poco = newPoco
            };

            connection.Save(otherMany);
            var pocos =
                connection.Select <FolkeTuple <TestPoco, TestManyPoco> >()
                .All(x => x.Item0)
                .All(x => x.Item1)
                .From(x => x.Item0)
                .RightJoin(x => x.Item1)
                .On(x => x.Item1.Poco == x.Item0)
                .ToList();

            Assert.Equal(2, pocos.Count);
            Assert.Equal(newPoco.Name, pocos[0].Item0.Name);
            Assert.Equal(newMany.Toto, pocos[0].Item1.Toto);
            Assert.Equal(newPoco, pocos[0].Item1.Poco);
            Assert.Equal(newPoco.Name, pocos[1].Item0.Name);
            Assert.Equal(otherMany.Toto, pocos[1].Item1.Toto);
            Assert.Equal(newPoco, pocos[1].Item1.Poco);
        }
예제 #2
0
        public void Select_TableType_InnerJoinOnId_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);
            var otherMany = new TestManyPoco {
                Toto = "OtherToto"
            };

            connection.Save(otherMany);
            var pocos =
                connection.Select <TestManyPoco>()
                .All()
                .All(x => x.Poco)
                .From()
                .InnerJoin(x => x.Poco).OnId(x => x.Poco).ToList();

            Assert.Equal(1, pocos.Count);
            Assert.Equal(newPoco.Name, pocos[0].Poco.Name);
            Assert.Equal(newMany.Toto, pocos[0].Toto);
        }
예제 #3
0
        public void Select_TypeThatIsNotATable_AllFieldsFromProperties_JoinOnStringOrderByString_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);
            var newMany2 = new TestManyPoco {
                Toto = "Tutu", Poco = newPoco
            };

            connection.Save(newMany2);

            connection.Cache.Clear();

            var manies = connection.Select <TestNotATable>().All(x => x.Poco).All(x => x.Many).From(x => x.Poco)
                         .LeftJoin(x => x.Many).On(x => x.Many.Poco == x.Poco).AndOn(x => x.Many.Toto == "Titi").OrderBy(x => x.Poco.Name).ToList();

            Assert.Equal(1, manies.Count);
            Assert.Equal(newPoco.Name, manies[0].Poco.Name);
            Assert.Equal(null, manies[0].Many);
        }
예제 #4
0
        public void Select_Tuple_FromLeftJoinOnId_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);
            var pocos =
                connection.Select <FolkeTuple <TestPoco, TestManyPoco> >()
                .All(x => x.Item0)
                .All(x => x.Item1)
                .From(x => x.Item0)
                .LeftJoin(x => x.Item1).On(x => x.Item1.Poco == x.Item0).ToList();

            Assert.Equal(1, pocos.Count);
            Assert.NotNull(pocos[0].Item0);
            Assert.Equal(newPoco.Name, pocos[0].Item0.Name);
            Assert.Equal(newMany.Toto, pocos[0].Item1.Toto);
            Assert.Equal(newPoco, pocos[0].Item1.Poco);
        }
예제 #5
0
        public void Load_WithAutoJoin()
        {
            var onePoco = new TestPoco {
                Name = "One"
            };

            connection.Save(onePoco);
            var twoPoco = new TestPoco {
                Name = "Two"
            };

            connection.Save(twoPoco);
            var three = new TestManyPoco {
                Toto = "Three", Poco = onePoco
            };

            connection.Save(three);
            var all = new TestMultiPoco {
                Name = "All", One = onePoco, Three = three, Two = twoPoco
            };

            connection.Save(all);

            connection.Cache.Clear();

            var multi = connection.Load <TestMultiPoco>(all.Id, x => x.One, x => x.Two, x => x.Three);

            Assert.Equal(all.Name, multi.Name);
            Assert.Equal(onePoco.Name, multi.One.Name);
            Assert.Equal(twoPoco.Name, multi.Two.Name);
            Assert.Equal(three.Toto, multi.Three.Toto);
        }
예제 #6
0
        public void SelectAllFrom_TableType_WhereObject_ReturnedItemsHaveReferenceToCachedItem_List()
        {
            var newPoco = new TestPoco {
                Name = null
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);

            var manies = connection.SelectAllFrom <TestManyPoco>().Where(t => t.Poco == newPoco).ToList();

            Assert.Equal(1, manies.Count);
            Assert.Equal(newPoco, manies[0].Poco);
        }
예제 #7
0
        public void Select_OneColumnAndIdInTableWithForeignKeys_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);

            connection.Cache.Clear();

            var response = connection.Select <TestManyPoco>().Values(x => x.Id).Values(x => x.Toto).From().ToList();

            Assert.Equal(newMany.Toto, response[0].Toto);
        }
예제 #8
0
        public void Select_TypeThatIsNotATable_AllFieldsFromProperties_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);

            var manies = connection.Select <TestNotATable>().All(x => x.Poco).All(x => x.Many).From(x => x.Many)
                         .LeftJoin(x => x.Poco).On(x => x.Many.Poco == x.Poco).ToList();

            Assert.Equal(newPoco.Name, manies[0].Poco.Name);
            Assert.Equal(newMany.Toto, manies[0].Many.Toto);
        }
예제 #9
0
        public void SelectAllFrom_TableTypeAndAutoJoin_WhereString_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);

            connection.Cache.Clear();

            var manies = connection.SelectAllFrom <TestManyPoco>(t => t.Poco).Where(t => t.Toto == "Toto").ToList();

            Assert.Equal(1, manies.Count);
            Assert.Equal(newPoco.Id, manies[0].Poco.Id);
            Assert.Equal(newPoco.Name, manies[0].Poco.Name);
        }
예제 #10
0
        public void Select_TableType_LeftJoinOnIdWhereString_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);

            connection.Cache.Clear();

            var manies = connection.Select <TestManyPoco>().All().All(x => x.Poco).From().LeftJoinOnId(x => x.Poco).Where(t => t.Toto == "Toto").ToList();

            Assert.Equal(1, manies.Count);
            Assert.Equal(newPoco.Id, manies[0].Poco.Id);
            Assert.Equal(newPoco.Name, manies[0].Poco.Name);
        }
예제 #11
0
        public void Select_Tuple_WhereExistsSubQuery_List()
        {
            var newPoco = new TestPoco {
                Name = "Name"
            };

            connection.Save(newPoco);
            var newMany = new TestManyPoco {
                Toto = "Toto", Poco = newPoco
            };

            connection.Save(newMany);
            var otherPoco = new TestPoco {
                Name = "OtherName"
            };

            connection.Save(otherPoco);

            var pocos = connection.Select <FolkeTuple <TestPoco, TestManyPoco> >().All(x => x.Item0).From(x => x.Item0)
                        .WhereExists(sub => sub.All(x => x.Item1).From(x => x.Item1).Where(x => x.Item1.Poco == x.Item0)).ToList();

            Assert.Equal(1, pocos.Count);
            Assert.Equal(newPoco.Name, pocos[0].Item0.Name);
        }