Esempio n. 1
0
 internal static string GetSource<T1>(QuerySet<T1> q1)
 {
     if (!string.IsNullOrEmpty(q1.datasource))
     {
         return q1.datasource;
     }
     if (q1.fields.Count > 0 || (!string.IsNullOrEmpty(q1.where)))
     {
         return "(" + q1.ToSQLString() + ")";
     }
     else
     {
         return Globals.Compiler.GetQName(q1.Schema, q1.table_name);
     }
     throw new NotImplementedException();
 }
Esempio n. 2
0
        private static QuerySet <T> BuilCrossJoin <T1, T2, T>(QuerySet <T1> qr1, QuerySet <T2> qr2, Expression <Func <T1, T2, T> > resultSelector)
        {
            var Params = new List <object>();

            var retQr = new QuerySet <T>();

            retQr.sequenceJoin = 1;
            var table1 = "T" + retQr.sequenceJoin.ToString();

            retQr.sequenceJoin++;
            var table2  = "T" + retQr.sequenceJoin.ToString();
            var source1 = Globals.Compiler.CreateAliasTable(Globals.Compiler.GetQName(qr1.Schema, qr1.GetTableName()), Globals.Compiler.GetQName("", table1));
            var source2 = Globals.Compiler.CreateAliasTable(Globals.Compiler.GetQName(qr1.Schema, qr2.GetTableName()), Globals.Compiler.GetQName("", table2));

            if (qr1.GetFields().Count > 0 || (!string.IsNullOrEmpty(((QuerySet <T1>)qr1).where)))
            {
                source1 = Globals.Compiler.CreateAliasTable("(" + qr1.ToSQLString() + ")", Globals.Compiler.GetQName("", table1));
            }
            if (qr2.GetFields().Count > 0 || (!string.IsNullOrEmpty(((QuerySet <T2>)qr2).where)))
            {
                source2 = Globals.Compiler.CreateAliasTable("(" + qr2.ToSQLString() + ")", Globals.Compiler.GetQName("", table2));
            }

            for (var i = 0; i < qr2.GetParams().Count; i++)
            {
                var nIndex = qr1.GetParams().Count + Params.Count + i;
                source2 = source2.Replace("{" + i.ToString() + "}", "{$##" + nIndex.ToString() + "##$}");
            }
            string FromSource = source1 + "," + source2;

            FromSource = FromSource.Replace("{$##", "{").Replace("##$}", "}");
            retQr.SetDataSource(FromSource);
            retQr.Params.AddRange(qr1.GetParams());
            retQr.Params.AddRange(Params);
            retQr.Params.AddRange(qr2.GetParams());
            return(retQr);
        }