// <summary> // Determine whether the given CLR type is legal for an ObjectParameter or constant // DbExpression. // </summary> private bool TryGetTypeUsageForTerminal(Expression expression, out TypeUsage typeUsage) { DebugCheck.NotNull(expression); var type = expression.Type; if (_rootContext.Perspective.TryGetTypeByName( TypeSystem.GetNonNullableType(type).FullNameWithNesting(), false, // bIgnoreCase out typeUsage) && (TypeSemantics.IsScalarType(typeUsage))) { if (expression.NodeType == ExpressionType.Convert) { type = ((UnaryExpression)expression).Operand.Type; } if (type.IsValueType && Nullable.GetUnderlyingType(type) == null && TypeSemantics.IsNullable(typeUsage)) { typeUsage = typeUsage.ShallowCopy( new FacetValues { Nullable = false }); } return(true); } typeUsage = null; return(false); }
// <summary> // Determine whether the given CLR type is legal for an ObjectParameter or constant // DbExpression. // </summary> private bool TryGetTypeUsageForTerminal(Type type, out TypeUsage typeUsage) { DebugCheck.NotNull(type); if (_rootContext.Perspective.TryGetTypeByName( TypeSystem.GetNonNullableType(type).FullNameWithNesting(), false, // bIgnoreCase out typeUsage) && (TypeSemantics.IsScalarType(typeUsage))) { if (type.IsValueType && Nullable.GetUnderlyingType(type) == null && TypeSemantics.IsNullable(typeUsage)) { typeUsage = typeUsage.ShallowCopy( new FacetValues { Nullable = false }); } return(true); } typeUsage = null; return(false); }
internal DbExpression(DbExpressionKind kind, TypeUsage type, bool forceNullable = true) { DbExpression.CheckExpressionKind(kind); this._kind = kind; if (forceNullable && !TypeSemantics.IsNullable(type)) { type = type.ShallowCopy(new FacetValues() { Nullable = (FacetValueContainer <bool?>) new bool?(true) }); } this._type = type; }
internal DbExpression(DbExpressionKind kind, TypeUsage type) { CheckExpressionKind(kind); _kind = kind; Debug.Assert(type != null, string.Format(CultureInfo.InvariantCulture, "{0}.Type is null in DbExpression constructor", this.GetType().Name)); if (!TypeSemantics.IsNullable(type)) { type = type.ShallowCopy(new FacetValues { Nullable = true }); } Debug.Assert(type.IsReadOnly, "Editable type metadata specified for DbExpression.Type"); this._type = type; }
internal DbExpression(DbExpressionKind kind, TypeUsage type, bool forceNullable = true) { CheckExpressionKind(kind); _kind = kind; DebugCheck.NotNull(type); if (forceNullable && !TypeSemantics.IsNullable(type)) { type = type.ShallowCopy( new FacetValues { Nullable = true }); } Debug.Assert(type.IsReadOnly, "Editable type metadata specified for DbExpression.Type"); _type = type; }
private bool TryGetTypeUsageForTerminal(Expression expression, out TypeUsage typeUsage) { Type type = expression.Type; if (this._rootContext.Perspective.TryGetTypeByName(TypeSystem.GetNonNullableType(type).FullNameWithNesting(), false, out typeUsage) && TypeSemantics.IsScalarType(typeUsage)) { if (expression.NodeType == ExpressionType.Convert) { type = ((UnaryExpression)expression).Operand.Type; } if (type.IsValueType && Nullable.GetUnderlyingType(type) == (Type)null && TypeSemantics.IsNullable(typeUsage)) { typeUsage = typeUsage.ShallowCopy(new FacetValues() { Nullable = (FacetValueContainer <bool?>) new bool?(false) }); } return(true); } typeUsage = (TypeUsage)null; return(false); }
// This will update the sentinel values in the facets if required private static void UpdateSentinelValuesInFacets(ref TypeUsage typeUsage) { // For string and decimal types, replace the sentinel by the max possible value var primitiveType = (PrimitiveType)typeUsage.EdmType; if (primitiveType.PrimitiveTypeKind == PrimitiveTypeKind.String || primitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Binary) { var maxLengthFacet = typeUsage.Facets[DbProviderManifest.MaxLengthFacetName]; if (Helper.IsUnboundedFacetValue(maxLengthFacet)) { typeUsage = typeUsage.ShallowCopy( new FacetValues { MaxLength = Helper.GetFacet( primitiveType.FacetDescriptions, DbProviderManifest.MaxLengthFacetName).MaxValue }); } } }
// <summary> // Determine whether the given CLR type is legal for an ObjectParameter or constant // DbExpression. // </summary> private bool TryGetTypeUsageForTerminal(Expression expression, out TypeUsage typeUsage) { DebugCheck.NotNull(expression); var type = expression.Type; if (_rootContext.Perspective.TryGetTypeByName( TypeSystem.GetNonNullableType(type).FullNameWithNesting(), false, // bIgnoreCase out typeUsage) && (TypeSemantics.IsScalarType(typeUsage))) { if (expression.NodeType == ExpressionType.Convert) { type = ((UnaryExpression)expression).Operand.Type; } if (type.IsValueType && Nullable.GetUnderlyingType(type) == null && TypeSemantics.IsNullable(typeUsage)) { typeUsage = typeUsage.ShallowCopy( new FacetValues { Nullable = false }); } return true; } typeUsage = null; return false; }