protected Expression VisitJetConvertExpression(SqlUnaryExpression convertExpression) { var typeMapping = convertExpression.TypeMapping; if (typeMapping == null) { throw new InvalidOperationException(RelationalStrings.UnsupportedType(convertExpression.Type.ShortDisplayName())); } if (_convertMappings.TryGetValue(typeMapping.ClrType.Name, out var function)) { Visit( _sqlExpressionFactory.NullChecked( convertExpression.Operand, _sqlExpressionFactory.Function( function, new[] { convertExpression.Operand }, typeMapping.ClrType))); return(convertExpression); } if (typeMapping.ClrType.Name == nameof(String)) { Sql.Append("("); Visit(convertExpression.Operand); Sql.Append(@" & '')"); return(convertExpression); } throw new InvalidOperationException($"Cannot cast to CLR type '{typeMapping.ClrType.Name}' with Jet."); }
protected Expression VisitJetConvertExpression(SqlUnaryExpression convertExpression) { var typeMapping = convertExpression.TypeMapping; if (typeMapping == null) { throw new InvalidOperationException(RelationalStrings.UnsupportedType(convertExpression.Type.ShortDisplayName())); } // We are explicitly converting to the target type (convertExpression.Type) and not the CLR type of the // accociated type mapping. This allows for conversions on the database side (e.g. CDBL()) but handling // of the returned value using a different (unaligned) type mapping (e.g. date/time related ones). if (_convertMappings.TryGetValue(convertExpression.Type.Name, out var function)) { Visit( _sqlExpressionFactory.NullChecked( convertExpression.Operand, _sqlExpressionFactory.Function( function, new[] { convertExpression.Operand }, false, new[] { false }, typeMapping.ClrType))); return(convertExpression); } if (typeMapping.ClrType.Name == nameof(String)) { Sql.Append("("); Visit(convertExpression.Operand); Sql.Append(@" & '')"); return(convertExpression); } throw new InvalidOperationException($"Cannot cast to CLR type '{typeMapping.ClrType.Name}' with Jet."); }