예제 #1
0
        public long Count()
        {
            Console.WriteLine("IBook1Sheet1Queryable.Count");

            var z = new IBook1Sheet1Queryable
            {
                Context     = this,
                ApplySelect =
                    x =>
                {
                    x.SelectCommand = "select count (*) ";
                }
            };

            var sql = ToSQL(z);

            Console.WriteLine();
            Console.WriteLine(new { sql });

            return(10);
        }
예제 #2
0
        public static string ToSQL(IBook1Sheet1Queryable q)
        {
            // first find the root and then work backwards to add the new filters

            Book1Sheet1 c = null;

            Action <IBook1Sheet1Queryable> y = null;

            y = x =>
            {
                // we wen too far, bail
                if (x == null)
                {
                    return;
                }

                // we found the root!
                if (x is Book1Sheet1)
                {
                    c = (Book1Sheet1)x;
                    return;
                }

                y(x.Context);

                // we will be modifying the original mutable object fields. reset for reuse!
                // ok. time to do the modify

                // what are we? a where clause?
                // can we merge the apply methods into one?
                if (x.ApplyWhereExpression != null)
                {
                    x.ApplyWhereExpression(c);
                    return;
                }

                if (x.ApplyOrderByDescending != null)
                {
                    x.ApplyOrderByDescending(c);
                    return;
                }

                if (x.ApplyTake != null)
                {
                    x.ApplyTake(c);
                    return;
                }

                if (x.ApplySelect != null)
                {
                    x.ApplySelect(c);
                    return;
                }
            };

            y(q);

            var w = new StringBuilder();

            w.AppendLine(c.SelectCommand);
            w.AppendLine(c.FromCommand);
            w.AppendLine(c.WhereCommand);
            w.AppendLine(c.OrderByCommand);
            w.AppendLine(c.LimitCommand);

            return(w.ToString());
        }