示例#1
0
        public Expression CastMethod(CastMethod method, LiteralExpression[] arguments)
        {
            Debug.Assert(arguments[1].LiteralType == LiteralType.String);

            if (arguments[0].LiteralType == LiteralType.Null)
            {
                return(arguments[0]);
            }

            var type = LiteralUtil.GetCompatibleType((string)arguments[1].Value);

            try
            {
                return(new LiteralExpression(Convert.ChangeType(arguments[0].Value, type, CultureInfo.InvariantCulture)));
            }
            catch (Exception ex)
            {
                throw new ODataException(
                          String.Format(
                              ErrorMessages.Method_CannotCast, arguments[1].Value
                              ),
                          ex
                          );
            }
        }
示例#2
0
        public override IProjection CastMethod(CastMethod method, Expression[] arguments)
        {
            var projection = ProjectionVisitor.CreateProjection(arguments[0]);

            switch (LiteralUtil.CoerceString((LiteralExpression)arguments[1]))
            {
            case "Edm.Byte":
            case "Edm.SByte":
            case "Edm.Int16":
            case "Edm.Int32":
                return(new SqlFunctionProjection("round", NHibernateUtil.Int32, projection));

            case "Edm.Int64":
                return(new SqlFunctionProjection("round", NHibernateUtil.Int64, projection));

            default:
                return(projection);
            }
        }
 public virtual TResult CastMethod(CastMethod method, Expression[] arguments)
 {
     throw new QueryNotSupportException();
 }