예제 #1
0
        internal ODataExpression(ODataExpressionKind kind, ODataExpressionType type, Type clrType)
        {
            Throw.IfNull(clrType, "clrType");
            Throw.If(!type.IsCompatibleWith(clrType), "clrType must be compatible with kind");

            this.Kind    = kind;
            this.Type    = type;
            this.ClrType = clrType;
        }
예제 #2
0
        internal ODataExpression(ODataExpressionKind kind, ODataExpressionType type, Type clrType)
        {
            Throw.IfNull(clrType, "clrType");
            Throw.If(!type.IsCompatibleWith(clrType), "clrType must be compatible with kind");

            this.Kind = kind;
            this.Type = type;
            this.ClrType = clrType;
        }
예제 #3
0
        public static bool IsImplicityCastableTo(this ODataExpressionType @this, ODataExpressionType that)
        {
            // can't cast to null, since it's not really a type
            var result = that != ODataExpressionType.Null &&
                         (
                // null can be implicitly cast to any type
                @this == ODataExpressionType.Null ||
                @this.ToClrType().IsImplicitlyCastableTo(that.ToClrType())
                         );

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Maps <see cref="ODataExpressionType"/>s to SqlServer types
        /// </summary>
        protected internal override string GetSqlTypeName(ODataExpressionType oDataType)
        {
            switch (oDataType)
            {
            case ODataExpressionType.Binary:
                return("VARBINARY(MAX)");

            case ODataExpressionType.Boolean:
                return("BIT");

            case ODataExpressionType.Byte:
                return("TINYINT");

            case ODataExpressionType.DateTime:
                return("DATETIME");

            case ODataExpressionType.DateTimeOffset:
                return("DATETIMEOFFSET");

            case ODataExpressionType.Decimal:
                // basing this off NHibernate mapping referenced here
                // http://stackoverflow.com/questions/3152439/what-is-a-good-mapping-of-net-decimal-to-sql-server-decimal
                return("DECIMAL(19, 5)");

            case ODataExpressionType.Double:
                return("FLOAT");

            case ODataExpressionType.Guid:
                return("UNIQUEIDENTIFIER");

            case ODataExpressionType.Int16:
                return("SMALLINT");

            case ODataExpressionType.Int32:
                return("INT");

            case ODataExpressionType.Int64:
                return("BIGINT");

            case ODataExpressionType.Single:
                // based on http://stackoverflow.com/questions/546150/float-in-database-to-in-net
                return("REAL");

            case ODataExpressionType.String:
                return("NVARCHAR(MAX)");

            case ODataExpressionType.Time:
                return("TIME");

            default:
                throw new NotSupportedException("OData type " + oDataType + " cannot be translated to SQL");
            }
        }
예제 #5
0
        internal static bool IsCompatibleWith(this ODataExpressionType @this, Type clrType)
        {
            Throw.IfNull(clrType, "clrType");

            if (@this == ODataExpressionType.Null)
            {
                return(clrType.CanBeNull()); // all nullable types are compatible with the null type
            }

            var mappedODataType = clrType.ToODataExpressionType();

            return(mappedODataType == @this);
        }
예제 #6
0
        public static Type ToClrType(this ODataExpressionType @this)
        {
            if (@this == ODataExpressionType.Null)
            {
                return(null);
            }

            Type type;

            if (ODataToClrTypes.TryGetValue(@this, out type))
            {
                return(type);
            }

            throw new ArgumentException("Expression type " + @this + " does not map to a Clr type");
        }
예제 #7
0
        public static bool IsNumeric(this ODataExpressionType @this)
        {
            switch (@this)
            {
            case ODataExpressionType.Byte:
            case ODataExpressionType.Decimal:
            case ODataExpressionType.Double:
            case ODataExpressionType.Int16:
            case ODataExpressionType.Int32:
            case ODataExpressionType.Int64:
            case ODataExpressionType.SByte:
            case ODataExpressionType.Single:
                return(true);

            default:
                return(false);
            }
        }
예제 #8
0
 internal ODataConstantExpression(object value, ODataExpressionType type, Type clrType)
     : base(ODataExpressionKind.Constant, type, clrType)
 {
     this.Value = value;
 }
예제 #9
0
 public static bool IsPrimitive(this ODataExpressionType @this)
 {
     return(@this >= ODataExpressionType.Binary && @this <= ODataExpressionType.DateTimeOffset);
 }
예제 #10
0
 /// <summary>
 /// Gets the database name for the given <see cref="ODataExpressionType"/>. Throws <see cref="NotSupportedException"/>
 /// if no database type maps to that type
 /// </summary>
 protected internal abstract string GetSqlTypeName(ODataExpressionType oDataType);
예제 #11
0
 internal ODataConstantExpression(object value, ODataExpressionType type, Type clrType)
     : base(ODataExpressionKind.Constant, type, clrType)
 {
     this.Value = value;
 }