Beispiel #1
0
        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
                       ));
        }
Beispiel #2
0
        public void Setup()
        {
            TestEntity = new Entity("table_name", new List<Column>(), typeof(TestEntity), null, new List<System.Type>(), 1);
            var col1 = new Column("column1", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);
            col1.Entity = TestEntity;
            var col2 = new Column("column2", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);
            col2.Entity = TestEntity;
            TestColumns = new List<Column>() { col1, col2 };

            UpdateStatements = new List<UpdateColumnStatement>() {
                    new UpdateColumnStatement(
                        "column1",
                        new ValueExpression("othervalue", PreparedStatementTypeMapper.Map(typeof(string)), "a")
                    ),
                    new UpdateColumnStatement(
                        "column2",
                        new ValueExpression("newValue", PreparedStatementTypeMapper.Map(typeof(string)), "b")
                    )
                };

            WhereFilters = new List<IWhereFilter>
            {
                BinaryExpression.Eq(
                    new ColumnExpression("column2"),
                    new ValueExpression("test", PreparedStatementTypeMapper.Map(typeof(string)), "test2")
                )
            };
        }
Beispiel #3
0
        public void Setup()
        {
            TestEntity = new Entity("table_name", new List <Column>(), typeof(TestEntity), null, new List <System.Type>(), 1);
            var col1 = new Column("column1", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);

            col1.Entity = TestEntity;
            var col2 = new Column("column2", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);

            col2.Entity = TestEntity;
            TestColumns = new List <Column>()
            {
                col1, col2
            };
        }
Beispiel #4
0
        public void TestSelectWhere()
        {
            var where = BinaryExpression.GT(
                new ColumnExpression("column1"),
                new ValueExpression(5, PreparedStatementTypeMapper.Map(typeof(int)), "test")
                );

            var selectQuery = new SelectQuery <TestEntity>(
                null,
                TestEntity,
                TestColumns,
                new List <IWhereFilter>()
            {
                where
            },
                new List <Join>());

            Assert.AreEqual("SELECT t1.column1, t1.column2 FROM table_name t1 WHERE t1.column1 > @test;", selectQuery.AsSqlString());
        }
Beispiel #5
0
        public void Setup()
        {
            TestEntity = new Entity("table_name", new List <Column>(), typeof(TestEntity), null, new List <Type>(), 1);
            var col1 = new Column("column1", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);

            col1.Entity = TestEntity;
            var col2 = new Column("column2", null, null, null, new OrmDbType("text", PreparedStatementTypeMapper.Map(typeof(string))), false);

            col2.Entity = TestEntity;
            TestColumns = new List <Column>()
            {
                col1, col2
            };

            WithStatements = new List <WithStatement>()
            {
                new WithStatement(
                    "column1",
                    new ValueExpression("othervalue", PreparedStatementTypeMapper.Map(typeof(string)), "a")
                    ),
            };
        }
Beispiel #6
0
 public static List <Column> BuildInterimColumns(ManyToMany m, Type from, Type to, ITypeMapper typeMapper)
 {
     return(new List <Column>()
     {
         new Column(
             m.ForeignKeyNear,
             new Fk(from),
             new HashSet <Constraint>(),
             null,
             new OrmDbType(typeMapper.GetForeignKeyType(), PreparedStatementTypeMapper.Map(from)),
             true
             ),
         new Column(
             m.ForeignKeyFar,
             new Fk(to),
             new HashSet <Constraint>(),
             null,
             new OrmDbType(typeMapper.GetForeignKeyType(), PreparedStatementTypeMapper.Map(from)),
             true
             )
     });
 }
Beispiel #7
0
 public ValueExpression(object value)
     : this(value, PreparedStatementTypeMapper.Map(value.GetType()))
 {
 }