Пример #1
0
        internal override SqlExpression VisitFunctionCall(SqlFunctionCall fc)
        {
            SqlExpression first = base.VisitFunctionCall(fc);

            if (first is SqlFunctionCall)
            {
                var expr = (SqlFunctionCall)first;
                if (expr.Name == "LEN")
                {
                    SqlExpression expression2 = expr.Arguments[0];
                    if (expression2.SqlType.IsLargeType && !expression2.SqlType.SupportsLength)
                    {
                        first = this.sql.DATALENGTH(expression2);
                        if (expression2.SqlType.IsUnicodeType)
                        {
                            first = sql.ConvertToInt(sql.Divide(first, sql.ValueFromObject(2, expression2.SourceExpression)));
                        }
                    }
                }

                Type closestRuntimeType = expr.SqlType.GetClosestRuntimeType();
                //if (expr.ClrType != closestRuntimeType)
                if (Type.GetTypeCode(expr.ClrType) != Type.GetTypeCode(closestRuntimeType))
                {
                    first = sql.ConvertTo(expr.ClrType, expr);
                }
            }
            return(first);
        }