Esempio n. 1
0
        private static bool TestSelectDogsWithToies2()
        {
            bool result = false;

            using (IDbConnection conn = new SqlConnection(DbConfigs.ConnectionString))
            {
                conn.Open();
                string sql = @"select * from TestTable1 a 
                                select * from TestTable1 a inner join TestTable2 b on a.Id = b.TT1_Id";

                var dogs = conn.QueryMultiple(sql).Map <Dog, Toy, int>(
                    dog => dog.Id,
                    toy => toy.TT1_Id,
                    (dog, toies) => {
                    dog.Toies.AddRange(toies);
                    if (toies != null)
                    {
                        foreach (var toy in toies)
                        {
                            toy.Owner = dog;
                        }
                    }
                });
                DogHelper.TraceDogs(dogs);
            }
            return(result);
        }
Esempio n. 2
0
        private static bool TestSelect2()
        {
            bool result = false;

            using (IDbConnection conn = new SqlConnection(DbConfigs.ConnectionString))
            {
                conn.Open();
                var dogs = conn.Query <Dog>("select * from TestTable1");
                DogHelper.TraceDogs(dogs);
            }
            return(result);
        }
Esempio n. 3
0
        private static bool TestSelect1()
        {
            bool result = false;

            using (IDbConnection conn = new SqlConnection(DbConfigs.ConnectionString))
            {
                conn.Open();
                var dogs = conn.Query <Dog>("select 1 as Id, 2 as Name, 3 as Type");
                DogHelper.TraceDogs(dogs);
            }
            return(result);
        }
Esempio n. 4
0
        private static bool TestSelectDogsWithToies()
        {
            bool result = false;

            using (IDbConnection conn = new SqlConnection(DbConfigs.ConnectionString))
            {
                conn.Open();
                var dogs = conn.Query <Dog, Toy, Dog>("select * from TestTable1 a inner join TestTable2 b on a.Id = b.TT1_Id",
                                                      (dog, toy) =>
                {
                    dog.Toies.Add(toy);
                    if (toy != null)
                    {
                        toy.Owner = dog;
                    }
                    return(dog);
                });
                DogHelper.TraceDogs(dogs);
            }
            return(result);
        }