Exemple #1
0
        protected override Expression VisitUnary(UnaryExpression unaryExpression)
        {
            if (unaryExpression.NodeType == ExpressionType.ArrayLength &&
                unaryExpression.Operand.Type == typeof(byte[]))
            {
                var sqlExpression = base.Visit(unaryExpression.Operand) as SqlExpression;

                if (sqlExpression == null)
                {
                    return(null);
                }

                var isBinaryMaxDataType   = GetProviderType(sqlExpression) == "varbinary(max)" || sqlExpression is SqlParameterExpression;
                var dataLengthSqlFunction = SqlExpressionFactory.Function(
                    "DATALENGTH",
                    new[] { sqlExpression },
                    nullable: true,
                    argumentsPropagateNullability: new bool[] { true },
                    isBinaryMaxDataType ? typeof(long) : typeof(int));

                return(isBinaryMaxDataType
                    ? (Expression)SqlExpressionFactory.Convert(dataLengthSqlFunction, typeof(int))
                    : dataLengthSqlFunction);
            }

            return(base.VisitUnary(unaryExpression));
        }
Exemple #2
0
 public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger) =>
 instance.Type != ClrType
         ? null
         : SqlExpressionFactory.Convert(instance, returnType);