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; }
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); }
/// <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"); } }
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); }
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"); }
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); } }
internal ODataConstantExpression(object value, ODataExpressionType type, Type clrType) : base(ODataExpressionKind.Constant, type, clrType) { this.Value = value; }
public static bool IsPrimitive(this ODataExpressionType @this) { return(@this >= ODataExpressionType.Binary && @this <= ODataExpressionType.DateTimeOffset); }
/// <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);