コード例 #1
0
        public void ExecuteDeepParent()
        {
            Guid       g       = StopWatch.Start();
            SqlBuilder builder = SqlBuilder.Select()
                                 .From("Contact")
                                 .AllColumns(false)
                                 .SubSelect("Account", "AccountID", "AccountID", null, null, "Account")
                                 .AllColumns(false)
                                 .ConcatColumns("Address", ", ", "Address1", "PostalCode", "City")
                                 .InnerJoin("Contact").On("AccountID", SqlOperators.Equal, "AccountID")
                                 .ToTable().Column("ContactID")
                                 .Builder();

            Console.WriteLine(builder.ToSql());
            ResultTable result = builder.Execute();

            Console.WriteLine("ResulTable with {0} rows executed in {1}ms", result.Count, StopWatch.Stop(g, StopWatch.WatchTypes.Milliseconds));
            foreach (dynamic row in result.Where(x => x.Column <ResultTable>("Account").Count > 0).Take(50))
            {
                dynamic Parent = row.Column <ResultTable>("Account");
                if (Parent.Count > 0)
                {
                    Console.WriteLine("The Contact {0} is connected to the account {1} - {2}", row.Name, Parent[0].Name, Parent[0].Address);
                }
                else
                {
                    Console.WriteLine("The Contact {0} is not connected to an account", row.Name);
                }
            }
        }