internal static bool TryGetPrecision(TypeUsage type, out byte precision) { if (!TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Decimal)) { precision = 0; return(false); } return(TryGetByteFacetValue(type, ProviderManifest.PrecisionFacetName, out precision)); }
internal static bool TryGetScale(TypeUsage type, out byte scale) { if (!TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Decimal)) { scale = 0; return(false); } return(TryGetByteFacetValue(type, ProviderManifest.ScaleFacetName, out scale)); }
internal static bool TryGetIsUnicode(TypeUsage type, out bool isUnicode) { isUnicode = true; if (!TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.String)) { isUnicode = false; return(false); } return(true); }
internal static bool TryGetMaxLength(TypeUsage type, out int maxLength) { if (!TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.String) && !TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Binary)) { maxLength = 0; return(false); } // Binary and String FixedLength facets share the same name return(TryGetIntFacetValue(type, ProviderManifest.MaxLengthFacetName, out maxLength)); }
internal static void PopulateParameterFromTypeUsage(DbParameter parameter, TypeUsage type) { Check.NotNull(parameter, "parameter"); Check.NotNull(type, "type"); // parameter.Direction - take the default. we don't support output // parameters. parameter.Direction = ParameterDirection.Input; // parameter.IsNullable - from the NullableConstraintAttribute value parameter.IsNullable = TypeSemantics.IsNullable(type); // parameter.ParameterName - set by the caller; // parameter.SourceColumn - not applicable until we have a data adapter; // parameter.SourceColumnNullMapping - not applicable until we have a data adapter; // parameter.SourceVersion - not applicable until we have a data adapter; // parameter.Value - left unset; // parameter.DbType - determined by the TypeMapping; // parameter.Precision - from the TypeMapping; // parameter.Scale - from the TypeMapping; // parameter.Size - from the TypeMapping; Debug.Assert(null != type, "no type mapping?"); if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Binary)) { PopulateBinaryParameter(parameter, type, DbType.Binary); } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Boolean)) { parameter.DbType = DbType.Boolean; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Byte)) { parameter.DbType = DbType.Byte; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.DateTime)) { parameter.DbType = DbType.DateTime; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Decimal)) { PopulateDecimalParameter(parameter, type, DbType.Decimal); } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Double)) { parameter.DbType = DbType.Double; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Guid)) { parameter.DbType = DbType.Guid; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Single)) { parameter.DbType = DbType.Single; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Int16)) { parameter.DbType = DbType.Int16; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Int32)) { parameter.DbType = DbType.Int32; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Int64)) { parameter.DbType = DbType.Int64; } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.String)) { PopulateStringParameter(parameter, type); } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Time)) { throw ADP1.NotSupported(EntityRes.GetString(EntityRes.ProviderDoesNotSupportType, "Time")); } else if (TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.DateTimeOffset)) { throw ADP1.NotSupported(EntityRes.GetString(EntityRes.ProviderDoesNotSupportType, "DateTimeOffset")); } else { ADP1.NotSupported(" UnKnown data type"); } }