Ejemplo n.º 1
0
        public void ToDbType_WithNullableDateTimeOffset()
        {
            var actual = DbTypeMapper.ToDbType(typeof(DateTimeOffset?));

            //Assert
            actual.Should().Be(DbType.DateTimeOffset);
        }
Ejemplo n.º 2
0
        public void ToDbType_WithUInt32()
        {
            var actual = DbTypeMapper.ToDbType(typeof(uint));

            //Assert
            actual.Should().Be(DbType.UInt32);
        }
Ejemplo n.º 3
0
        public void ToDbType_WithNullableInt64()
        {
            var actual = DbTypeMapper.ToDbType(typeof(long?));

            //Assert
            actual.Should().Be(DbType.Int64);
        }
Ejemplo n.º 4
0
        public void ToDbType_WithXElement()
        {
            var actual = DbTypeMapper.ToDbType(typeof(XElement));

            //Assert
            actual.Should().Be(DbType.Xml);
        }
Ejemplo n.º 5
0
        public void ToDbType_WithNullableInt16()
        {
            var actual = DbTypeMapper.ToDbType(typeof(short?));

            //Assert
            actual.Should().Be(DbType.Int16);
        }
Ejemplo n.º 6
0
        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"
                }
            }
        }
Ejemplo n.º 7
0
        public void ToDbType_WithNullableDouble()
        {
            var actual = DbTypeMapper.ToDbType(typeof(double?));

            //Assert
            actual.Should().Be(DbType.Double);
        }
Ejemplo n.º 8
0
        public void ToDbType_WithString()
        {
            var actual = DbTypeMapper.ToDbType(typeof(string));

            //Assert
            actual.Should().Be(DbType.String);
        }
Ejemplo n.º 9
0
        public void ToDbType_WithUInt16()
        {
            var actual = DbTypeMapper.ToDbType(typeof(ushort));

            //Assert
            actual.Should().Be(DbType.UInt16);
        }
Ejemplo n.º 10
0
        public void ToDbType_WithNullableBoolean()
        {
            var actual = DbTypeMapper.ToDbType(typeof(bool?));

            //Assert
            actual.Should().Be(DbType.Boolean);
        }
Ejemplo n.º 11
0
        public void ToDbType_WithNullableByte()
        {
            var actual = DbTypeMapper.ToDbType(typeof(byte?));

            //Assert
            actual.Should().Be(DbType.Byte);
        }
Ejemplo n.º 12
0
        public void ToDbType_WithDateTime()
        {
            var actual = DbTypeMapper.ToDbType(typeof(DateTime));

            //Assert
            actual.Should().Be(DbType.DateTime);
        }
Ejemplo n.º 13
0
        public void ToDbType_WithMoney()
        {
            var actual = DbTypeMapper.ToDbType(typeof(Money));

            //Assert
            actual.Should().Be(DbType.Currency);
        }
Ejemplo n.º 14
0
        public void ToDbType_WithCharArray()
        {
            var actual = DbTypeMapper.ToDbType(typeof(char[]));

            //Assert
            actual.Should().Be(DbType.String);
        }
Ejemplo n.º 15
0
        public void ToDbType_WithByteArray()
        {
            var actual = DbTypeMapper.ToDbType(typeof(byte[]));

            //Assert
            actual.Should().Be(DbType.Binary);
        }
Ejemplo n.º 16
0
        public void ToDbType_WithUnknownType()
        {
            var actual = DbTypeMapper.ToDbType(typeof(DbTypeMapperTests));

            //Assert
            actual.Should().Be(DbType.Object);
        }
Ejemplo n.º 17
0
        public void ToDbType_WithSByte()
        {
            var actual = DbTypeMapper.ToDbType(typeof(sbyte));

            //Assert
            actual.Should().Be(DbType.SByte);
        }
Ejemplo n.º 18
0
        public void ToDbType_WithNullableChar()
        {
            var actual = DbTypeMapper.ToDbType(typeof(char?));

            //Assert
            actual.Should().Be(DbType.String);
        }
Ejemplo n.º 19
0
        public void ToDbType_WithSingle()
        {
            var actual = DbTypeMapper.ToDbType(typeof(float));

            //Assert
            actual.Should().Be(DbType.Single);
        }
Ejemplo n.º 20
0
        public void ToDbType_WithUInt64()
        {
            var actual = DbTypeMapper.ToDbType(typeof(ulong));

            //Assert
            actual.Should().Be(DbType.UInt64);
        }
Ejemplo n.º 21
0
        public void ToDbType_WithTimeSpan()
        {
            var actual = DbTypeMapper.ToDbType(typeof(TimeSpan));

            //Assert
            actual.Should().Be(DbType.Time);
        }
Ejemplo n.º 22
0
        public void ToDbType_WithNullableDecimal()
        {
            var actual = DbTypeMapper.ToDbType(typeof(decimal?));

            //Assert
            actual.Should().Be(DbType.Decimal);
        }
Ejemplo n.º 23
0
        public void ToDbType_WithNullableGuid()
        {
            var actual = DbTypeMapper.ToDbType(typeof(Guid?));

            //Assert
            actual.Should().Be(DbType.Guid);
        }
Ejemplo n.º 24
0
 /// <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);
 }
Ejemplo n.º 25
0
 /// <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);
 }
Ejemplo n.º 26
0
    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>());
    }
Ejemplo n.º 27
0
        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++;
            }
        }
Ejemplo n.º 28
0
    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>());
    }
Ejemplo n.º 29
0
        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)
                });
            }
        }
Ejemplo n.º 30
0
 public static IDictionary <string, SqlType> ToSqlColumns(this IEnumerable <PropertyInfo> properties)
 {
     return(properties.ToDictionary(p => p.Name, p => new SqlType(DbTypeMapper.GetDbType(p.PropertyType))));
 }