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]); }
static void Method_Guid_NewGuid(DbMethodCallExpression exp, SqlGenerator generator) { EnsureMethod(exp, UtilConstants.MethodInfo_Guid_NewGuid); generator._sqlBuilder.Append("NEWID()"); }
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]); }
static void Method_DateTime_AddHours(DbMethodCallExpression exp, SqlGenerator generator) { EnsureMethodDeclaringType(exp, UtilConstants.TypeOfDateTime); DbFunction_DATEADD(generator, "HOUR", exp); }
static void Method_DateTime_AddMilliseconds(DbMethodCallExpression exp, SqlGenerator generator) { EnsureMethodDeclaringType(exp, UtilConstants.TypeOfDateTime); DbFunction_DATEADD(generator, "MILLISECOND", exp); }
static void Method_LongCount(DbMethodCallExpression exp, SqlGenerator generator) { EnsureMethodDeclaringType(exp, typeof(AggregateFunctions)); Aggregate_LongCount(generator); }
static void Method_Average(DbMethodCallExpression exp, SqlGenerator generator) { EnsureMethodDeclaringType(exp, typeof(AggregateFunctions)); Aggregate_Average(generator, exp.Arguments.First(), exp.Method.ReturnType); }
static void Aggregate_Average(DbAggregateExpression exp, SqlGenerator generator) { Aggregate_Average(generator, exp.Parameters.First(), exp.Method.ReturnType); }
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"); }
static void Aggregate_Min(DbAggregateExpression exp, SqlGenerator generator) { Aggregate_Min(generator, exp.Arguments.First(), exp.Method.ReturnType); }
static void Aggregate_LongCount(DbAggregateExpression exp, SqlGenerator generator) { Aggregate_LongCount(generator); }
public virtual SqlGenerator CreateSqlGenerator() { return(SqlGenerator.CreateInstance()); }
public static void Aggregate_Average(SqlGenerator generator, DbExpression exp, Type retType) { AppendAggregateFunction(generator, exp, retType, "AVG", true); }
public static void Aggregate_Min(SqlGenerator generator, DbExpression exp, Type retType) { AppendAggregateFunction(generator, exp, retType, "MIN", false); }
public static void Aggregate_LongCount(SqlGenerator generator) { generator._sqlBuilder.Append("COUNT_BIG(1)"); }
static void Aggregate_Count(SqlGenerator generator) { generator._sqlBuilder.Append("COUNT(1)"); }