public void ToDbType_WithNullableDateTimeOffset() { var actual = DbTypeMapper.ToDbType(typeof(DateTimeOffset?)); //Assert actual.Should().Be(DbType.DateTimeOffset); }
public void ToDbType_WithUInt32() { var actual = DbTypeMapper.ToDbType(typeof(uint)); //Assert actual.Should().Be(DbType.UInt32); }
public void ToDbType_WithNullableInt64() { var actual = DbTypeMapper.ToDbType(typeof(long?)); //Assert actual.Should().Be(DbType.Int64); }
public void ToDbType_WithXElement() { var actual = DbTypeMapper.ToDbType(typeof(XElement)); //Assert actual.Should().Be(DbType.Xml); }
public void ToDbType_WithNullableInt16() { var actual = DbTypeMapper.ToDbType(typeof(short?)); //Assert actual.Should().Be(DbType.Int16); }
public override void Generate() { #line 37 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.ssdl.EntityTypeColumns.cst" /* * TODO: Actually, all this should die and become a bunch of polymorphic calls. */ foreach (var p in properties) { // TODO: implement IsNullable everywhere if (p is CompoundObjectProperty) { ApplyEntityTypeColumnDefs( ((CompoundObjectProperty)p).CompoundObjectDefinition.Properties.Cast <Property>().OrderBy(prop => prop.Name), Construct.NestedColumnName(p, prefix), schemaProvider); } else if (p is ObjectReferenceProperty) { throw new ArgumentException("properties", String.Format("contains ObjectReferenceProperty {0}, but this template cannot work with that", p)); } else { string propertyName = Construct.NestedColumnName(p, prefix); string sqlTypeName = schemaProvider.DbTypeToNative(DbTypeMapper.GetDbTypeForProperty(p.GetType())); string maxLengthAttr = String.Empty; if (p is StringProperty) { int maxLength = ((StringProperty)p).GetMaxLength(); if (maxLength != int.MaxValue) { // must have one space at the end maxLengthAttr = String.Format("MaxLength=\"{0}\" ", maxLength); } } string precScaleAttr = String.Empty; if (p is DecimalProperty) { DecimalProperty dp = (DecimalProperty)p; // must have one space at the end precScaleAttr = String.Format("Precision=\"{0}\" Scale=\"{1}\" ", dp.Precision, dp.Scale); } string nullableAttr = String.Empty; if (p.IsValueTypePropertySingle()) { // must have one space at the end nullableAttr = String.Format("Nullable=\"{0}\" ", ((Property)p).IsNullable().ToString().ToLowerInvariant()); } #line 87 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.ssdl.EntityTypeColumns.cst" this.WriteObjects(" <Property Name=\"", propertyName, "\" Type=\"", sqlTypeName, "\" ", maxLengthAttr, "", precScaleAttr, "", nullableAttr, "/>\r\n"); #line 89 "P:\zetbox\Zetbox.DalProvider.EF.Generator\Templates\EfModel\Model.ssdl.EntityTypeColumns.cst" } } }
public void ToDbType_WithNullableDouble() { var actual = DbTypeMapper.ToDbType(typeof(double?)); //Assert actual.Should().Be(DbType.Double); }
public void ToDbType_WithString() { var actual = DbTypeMapper.ToDbType(typeof(string)); //Assert actual.Should().Be(DbType.String); }
public void ToDbType_WithUInt16() { var actual = DbTypeMapper.ToDbType(typeof(ushort)); //Assert actual.Should().Be(DbType.UInt16); }
public void ToDbType_WithNullableBoolean() { var actual = DbTypeMapper.ToDbType(typeof(bool?)); //Assert actual.Should().Be(DbType.Boolean); }
public void ToDbType_WithNullableByte() { var actual = DbTypeMapper.ToDbType(typeof(byte?)); //Assert actual.Should().Be(DbType.Byte); }
public void ToDbType_WithDateTime() { var actual = DbTypeMapper.ToDbType(typeof(DateTime)); //Assert actual.Should().Be(DbType.DateTime); }
public void ToDbType_WithMoney() { var actual = DbTypeMapper.ToDbType(typeof(Money)); //Assert actual.Should().Be(DbType.Currency); }
public void ToDbType_WithCharArray() { var actual = DbTypeMapper.ToDbType(typeof(char[])); //Assert actual.Should().Be(DbType.String); }
public void ToDbType_WithByteArray() { var actual = DbTypeMapper.ToDbType(typeof(byte[])); //Assert actual.Should().Be(DbType.Binary); }
public void ToDbType_WithUnknownType() { var actual = DbTypeMapper.ToDbType(typeof(DbTypeMapperTests)); //Assert actual.Should().Be(DbType.Object); }
public void ToDbType_WithSByte() { var actual = DbTypeMapper.ToDbType(typeof(sbyte)); //Assert actual.Should().Be(DbType.SByte); }
public void ToDbType_WithNullableChar() { var actual = DbTypeMapper.ToDbType(typeof(char?)); //Assert actual.Should().Be(DbType.String); }
public void ToDbType_WithSingle() { var actual = DbTypeMapper.ToDbType(typeof(float)); //Assert actual.Should().Be(DbType.Single); }
public void ToDbType_WithUInt64() { var actual = DbTypeMapper.ToDbType(typeof(ulong)); //Assert actual.Should().Be(DbType.UInt64); }
public void ToDbType_WithTimeSpan() { var actual = DbTypeMapper.ToDbType(typeof(TimeSpan)); //Assert actual.Should().Be(DbType.Time); }
public void ToDbType_WithNullableDecimal() { var actual = DbTypeMapper.ToDbType(typeof(decimal?)); //Assert actual.Should().Be(DbType.Decimal); }
public void ToDbType_WithNullableGuid() { var actual = DbTypeMapper.ToDbType(typeof(Guid?)); //Assert actual.Should().Be(DbType.Guid); }
/// <summary> /// Adds a key column to the table from the specified type. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="columnName"></param> /// <param name="precision"></param> /// <param name="scale"></param> /// <returns></returns> public TableBuilder WithColumnFromType <T>(string columnName, int precision, int scale) { if (columnName == null) { throw new ArgumentNullException(nameof(columnName)); } Columns[columnName] = new SqlType(DbTypeMapper.GetDbType(typeof(T)), precision, scale); return(this); }
/// <summary> /// Adds a key column to the table from the specified type. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="keyColumnName"></param> /// <param name="isIdentity"></param> /// <returns></returns> public TableBuilder WithKeyColumnFromType <T>(string keyColumnName, bool isIdentity = false) { if (keyColumnName == null) { throw new ArgumentNullException(nameof(keyColumnName)); } Columns[keyColumnName] = new SqlType(DbTypeMapper.GetDbType(typeof(T)), isIdentity); KeyColumns.Add(keyColumnName); return(this); }
public void HandlerType_Does_Not_Implement_ITypeHandler_Does_Nothing() { // Arrange var handlerType = typeof(InvalidHandlerWithGenericParameter <>); var addTypeHandler = Substitute.For <IDbTypeMapper.AddGenericTypeHandler>(); var mapper = new DbTypeMapper(); // Act mapper.AddGenericTypeHandlers <string>(handlerType, addTypeHandler); // Assert addTypeHandler.DidNotReceive().Invoke(Arg.Any <Type>(), Arg.Any <SqlMapper.ITypeHandler>()); }
public Translator(SourceTable tbl, IDataReader source, IEnumerable <SourceColumn> srcColumns, Converter[] converter) { if (tbl == null) { throw new ArgumentNullException("tbl"); } if (source == null) { throw new ArgumentNullException("source"); } if (srcColumns == null) { throw new ArgumentNullException("srcColumns"); } //_tbl = tbl; _source = source; _srcColumns = srcColumns.ToArray(); _srcColumnsInfos = _srcColumns.Select( col => new SourceColumnInfo(DbTypeMapper.GetDbTypeForProperty(col.DestinationProperty.Last().GetType()), DbTypeMapper.GetDbType(col.DbType), col.DestinationProperty.Last() is EnumerationProperty, col.DestinationProperty.First() is CompoundObjectProperty)).ToArray(); _converter = converter != null?converter.ToDictionary(c => c.Column) : new Dictionary <SourceColumn, Converter>(); _resultColumnCount = _srcColumns.Length; if (typeof(IMigrationInfo).IsAssignableFrom(tbl.DestinationObjectClass.GetDataType())) { // TODO: That's a bad hack! _errorColIdx = _resultColumnCount; _resultColumnCount++; } else { _errorColIdx = -1; } foreach (var comp in srcColumns .Where(c => c.DestinationProperty.First() is CompoundObjectProperty) .GroupBy(c => c.DestinationProperty.First())) { foreach (var col in comp) { _compoundObjectSourceColumns[col.Name] = _resultColumnCount; } _resultColumnCount++; } }
public void Calls_AddTypeHandler_For_Each_Implementing_Property_Type() { // Arrange var handlerType = typeof(Handler <>); var addTypeHandler = Substitute.For <IDbTypeMapper.AddGenericTypeHandler>(); var mapper = new DbTypeMapper(); // Act mapper.AddGenericTypeHandlers <CustomBaseType>(handlerType, addTypeHandler); // Assert addTypeHandler.Received().Invoke(typeof(CustomType0), Arg.Any <SqlMapper.ITypeHandler>()); addTypeHandler.Received().Invoke(typeof(CustomType1), Arg.Any <SqlMapper.ITypeHandler>()); }
public IEnumerable <Column> GetTableColumns(TableRef tbl) { QueryLog.Debug("GetSchema(Columns)"); var columns = db.GetSchema(OleDbMetaDataCollectionNames.Columns, new string[] { null, null, tbl.Name, null }); foreach (DataRow col in columns.Rows) { int dt = (int)col["DATA_TYPE"]; Type type = DataTypes.ContainsKey(dt) ? DataTypes[dt].Type : typeof(string); int size = (int)(col["CHARACTER_MAXIMUM_LENGTH"] as long? ?? 0); if (size == 0 && (type == typeof(string) || type == typeof(byte[]))) { size = int.MaxValue; } yield return(new Column() { Name = (string)col["COLUMN_NAME"], Size = size, IsNullable = (bool)col["IS_NULLABLE"], Type = DbTypeMapper.GetDbType(type) }); } }
public static IDictionary <string, SqlType> ToSqlColumns(this IEnumerable <PropertyInfo> properties) { return(properties.ToDictionary(p => p.Name, p => new SqlType(DbTypeMapper.GetDbType(p.PropertyType)))); }