コード例 #1
0
        static void Method_DbFunctions_DiffMicroseconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_DbFunctions_DiffMicroseconds);

            DbFunction_DATEDIFF(generator, "MICROSECOND", exp.Arguments[0], exp.Arguments[1]);
        }
コード例 #2
0
        static void Method_Guid_NewGuid(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_Guid_NewGuid);

            generator._sqlBuilder.Append("NEWID()");
        }
コード例 #3
0
        static void Method_DbFunctions_DiffMinutes(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethod(exp, UtilConstants.MethodInfo_DbFunctions_DiffMinutes);

            DbFunction_DATEDIFF(generator, "MINUTE", exp.Arguments[0], exp.Arguments[1]);
        }
コード例 #4
0
        static void Method_DateTime_AddHours(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethodDeclaringType(exp, UtilConstants.TypeOfDateTime);

            DbFunction_DATEADD(generator, "HOUR", exp);
        }
コード例 #5
0
        static void Method_DateTime_AddMilliseconds(DbMethodCallExpression exp, SqlGenerator generator)
        {
            EnsureMethodDeclaringType(exp, UtilConstants.TypeOfDateTime);

            DbFunction_DATEADD(generator, "MILLISECOND", exp);
        }
コード例 #6
0
 static void Method_LongCount(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions));
     Aggregate_LongCount(generator);
 }
コード例 #7
0
 static void Method_Average(DbMethodCallExpression exp, SqlGenerator generator)
 {
     EnsureMethodDeclaringType(exp, typeof(AggregateFunctions));
     Aggregate_Average(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
コード例 #8
0
 static void Aggregate_Average(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_Average(generator, exp.Parameters.First(), exp.Method.ReturnType);
 }
コード例 #9
0
ファイル: SqlGenerator.cs プロジェクト: whw0828/EPASServer
        static void StringConcat(DbBinaryExpression exp, SqlGenerator generator)
        {
            MethodInfo method = exp.Method;

            List <DbExpression> operands = new List <DbExpression>();

            operands.Add(exp.Right);

            DbExpression    left = exp.Left;
            DbAddExpression e    = null;

            while ((e = (left as DbAddExpression)) != null && (e.Method == UtilConstants.MethodInfo_String_Concat_String_String || e.Method == UtilConstants.MethodInfo_String_Concat_Object_Object))
            {
                operands.Add(e.Right);
                left = e.Left;
            }

            operands.Add(left);

            DbExpression        whenExp     = null;
            List <DbExpression> operandExps = new List <DbExpression>(operands.Count);

            for (int i = operands.Count - 1; i >= 0; i--)
            {
                DbExpression operand = operands[i];
                DbExpression opBody  = operand;
                if (opBody.Type != UtilConstants.TypeOfString)
                {
                    // 需要 cast type
                    opBody = DbExpression.Convert(opBody, UtilConstants.TypeOfString);
                }

                DbExpression equalNullExp = DbExpression.Equal(opBody, UtilConstants.DbConstant_Null_String);

                if (whenExp == null)
                {
                    whenExp = equalNullExp;
                }
                else
                {
                    whenExp = DbExpression.AndAlso(whenExp, equalNullExp);
                }

                DbExpression thenExp = DbConstantExpression.StringEmpty;
                DbCaseWhenExpression.WhenThenExpressionPair whenThenPair = new DbCaseWhenExpression.WhenThenExpressionPair(equalNullExp, thenExp);

                List <DbCaseWhenExpression.WhenThenExpressionPair> whenThenExps = new List <DbCaseWhenExpression.WhenThenExpressionPair>(1);
                whenThenExps.Add(whenThenPair);

                DbExpression elseExp = opBody;

                DbCaseWhenExpression caseWhenExpression = DbExpression.CaseWhen(whenThenExps, elseExp, UtilConstants.TypeOfString);

                operandExps.Add(caseWhenExpression);
            }

            generator._sqlBuilder.Append("CASE", " WHEN ");
            whenExp.Accept(generator);
            generator._sqlBuilder.Append(" THEN ");
            DbConstantExpression.Null.Accept(generator);
            generator._sqlBuilder.Append(" ELSE ");

            generator._sqlBuilder.Append("(");

            for (int i = 0; i < operandExps.Count; i++)
            {
                if (i > 0)
                {
                    generator._sqlBuilder.Append(" + ");
                }

                operandExps[i].Accept(generator);
            }

            generator._sqlBuilder.Append(")");

            generator._sqlBuilder.Append(" END");
        }
コード例 #10
0
 static void Aggregate_Min(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_Min(generator, exp.Arguments.First(), exp.Method.ReturnType);
 }
コード例 #11
0
 static void Aggregate_LongCount(DbAggregateExpression exp, SqlGenerator generator)
 {
     Aggregate_LongCount(generator);
 }
コード例 #12
0
 public virtual SqlGenerator CreateSqlGenerator()
 {
     return(SqlGenerator.CreateInstance());
 }
コード例 #13
0
ファイル: SqlGenerator_Helper.cs プロジェクト: zyj0021/Chloe
 public static void Aggregate_Average(SqlGenerator generator, DbExpression exp, Type retType)
 {
     AppendAggregateFunction(generator, exp, retType, "AVG", true);
 }
コード例 #14
0
ファイル: SqlGenerator_Helper.cs プロジェクト: zyj0021/Chloe
 public static void Aggregate_Min(SqlGenerator generator, DbExpression exp, Type retType)
 {
     AppendAggregateFunction(generator, exp, retType, "MIN", false);
 }
コード例 #15
0
ファイル: SqlGenerator_Helper.cs プロジェクト: zyj0021/Chloe
 public static void Aggregate_LongCount(SqlGenerator generator)
 {
     generator._sqlBuilder.Append("COUNT_BIG(1)");
 }
コード例 #16
0
 static void Aggregate_Count(SqlGenerator generator)
 {
     generator._sqlBuilder.Append("COUNT(1)");
 }