public static SqlMetaData CreateSqlMetaData(string columnName, Type type, MetaDataCreationOptions metaDataCreationOptions) { Func <string, MetaDataCreationOptions, SqlMetaData> creator; if (SqlMetaDataCreators.TryGetValue(type, out creator) == false) { throw new InvalidOperationException($"No SqlMetaData was found for {type}"); } return(creator(columnName, metaDataCreationOptions)); }
private IMetaDataOptionsBuilder <TSource> SetMaxLength(LambdaExpression member, long maxLength) { if (maxLength <= 0) { throw new ArgumentException($"{nameof(maxLength)} must be positive"); } PropertiesSqlMetaDataOptions[GetMemberName(member)] = new MetaDataCreationOptions { MaxLength = maxLength }; return(this); }
private IMetaDataOptionsBuilder <TSource> SetAccuracy(LambdaExpression member, byte precision, byte scale) { if (scale > precision) { throw new ArgumentException($"{nameof(scale)} cannot be greater than {nameof(precision)}"); } PropertiesSqlMetaDataOptions[GetMemberName(member)] = new MetaDataCreationOptions { Precision = precision, Scale = scale }; return(this); }
static SqlTypesMapper() { SqlTypesMappings = new Dictionary <Type, SqlDbType>() .AddMap <byte>(SqlDbType.TinyInt) .AddMap <short>(SqlDbType.SmallInt) .AddMap <char>(SqlDbType.NChar) .AddMap <int>(SqlDbType.Int) .AddMap <long>(SqlDbType.BigInt) .AddMap <float>(SqlDbType.Real) .AddMap <double>(SqlDbType.Float) .AddMap <decimal>(SqlDbType.Decimal) .AddMap <bool>(SqlDbType.Bit) .AddMap <Guid>(SqlDbType.UniqueIdentifier) .AddMap <DateTime>(SqlDbType.DateTime) .AddMap <DateTimeOffset>(SqlDbType.DateTimeOffset) .AddMap <TimeSpan>(SqlDbType.Time) .AddMap <byte[]>(SqlDbType.VarBinary) .AddMap <char[]>(SqlDbType.NVarChar) .AddMap <string>(SqlDbType.NVarChar) .AddMap <object>(SqlDbType.Variant); DefaultArraysMetaDataCreationOptions = new MetaDataCreationOptions { MaxLength = -1 }; DefaultDecimalMetaDataCreationOptions = new MetaDataCreationOptions { Precision = 10, Scale = 2 }; SqlMetaDataCreators = new Dictionary <Type, Func <string, MetaDataCreationOptions, SqlMetaData> >() .AddCreator <byte>(CreatorForScalarTypes) .AddCreator <short>(CreatorForScalarTypes) .AddCreator <char>(CreatorForChar) .AddCreator <int>(CreatorForScalarTypes) .AddCreator <long>(CreatorForScalarTypes) .AddCreator <float>(CreatorForScalarTypes) .AddCreator <double>(CreatorForScalarTypes) .AddCreator <decimal>(CreatorForDecimal) .AddCreator <bool>(CreatorForScalarTypes) .AddCreator <Guid>(CreatorForScalarTypes) .AddCreator <DateTime>(CreatorForScalarTypes) .AddCreator <DateTimeOffset>(CreatorForScalarTypes) .AddCreator <byte[]>(CreatorForArrays) .AddCreator <string>(CreatorForArrays) .AddCreator <object>(CreatorForObject); }
private static SqlMetaData CreatorForObject(string columnName, SqlDbType sqlDbType, MetaDataCreationOptions metaDataCreationOptions) { return(new SqlMetaData(columnName, sqlDbType)); }
private static SqlMetaData CreatorForArrays(string columnName, SqlDbType sqlDbType, MetaDataCreationOptions metaDataCreationOptions) { if (metaDataCreationOptions != null && metaDataCreationOptions.MaxLength.HasValue == false) { throw new ArgumentNullException(nameof(metaDataCreationOptions.MaxLength)); } return(new SqlMetaData(columnName, sqlDbType, (metaDataCreationOptions ?? DefaultArraysMetaDataCreationOptions).MaxLength.Value)); }
private static SqlMetaData CreatorForDecimal(string columnName, SqlDbType sqlDbType, MetaDataCreationOptions metaDataCreationOptions) { if (metaDataCreationOptions != null && metaDataCreationOptions.Precision.HasValue == false) { throw new ArgumentNullException(nameof(metaDataCreationOptions.Precision)); } if (metaDataCreationOptions != null && metaDataCreationOptions.Scale.HasValue == false) { throw new ArgumentNullException(nameof(metaDataCreationOptions.Scale)); } var options = metaDataCreationOptions ?? DefaultDecimalMetaDataCreationOptions; return(new SqlMetaData(columnName, sqlDbType, options.Precision.Value, options.Scale.Value)); }
public static PrimitiveValuesList <TSource> Create <TSource>(string typeName, IEnumerable <TSource> source, MetaDataCreationOptions metaDataCreationOptions = null) where TSource : IComparable, IComparable <TSource>, IConvertible, IEquatable <TSource> { return(new PrimitiveValuesList <TSource>(typeName, source, metaDataCreationOptions)); }