/// <summary> /// Checks if the property return types in the DbSets are valid as a columntype. They either have to be able to be mapped by the TypeMapper /// or be of type of another DbSet or be an enum. /// </summary> /// <param name="columnTypes">Types to check</param> /// <param name="tableTypes">Types of other DbSets</param> /// <returns>true when valid, false when not</returns> private static bool ValidColumnTypes(IEnumerable <Type> columnTypes, IEnumerable <Type> tableTypes, ITypeMapper typeMapper) { return(columnTypes .Select(cType => cType.IsNonStringEnumerable() ? cType.GetGenericArguments()[0] : cType) .Where(columnType => string.IsNullOrEmpty(typeMapper.GetDbType(columnType)) && !columnType.IsEnum) .All(tableTypes.Contains)); }
private static OrmDbType DbType(Type t, List <Type> tableTypes, HashSet <Constraint> constraints, ITypeMapper typeMapper) { var ddlType = typeMapper.GetDbType(t); var pstmtType = PreparedStatementTypeMapper.Map(t); if (tableTypes.Any(tType => tType == t)) { ddlType = typeMapper.GetForeignKeyType(); pstmtType = PreparedStatementTypeMapper.GetForeignKeyType(); } if (constraints.Any(c => c.GetType() == typeof(Pk))) { ddlType = typeMapper.GetPrimaryKeyType(); } // because we always want to enforce enums to be text if (t.IsEnum) { ddlType = typeMapper.GetEnumType(); } return(new OrmDbType( ddlType, pstmtType )); }
public void TestNonExistent() { var e = new TestEntity(); Assert.AreEqual(null, _typeMapper.GetDbType(e.GetType())); }