コード例 #1
0
        public void Test_Object_Instance()
        {
            var instance = new ValuesInstance();

            var sql = Db <DB> .Sql(db =>
                                   Select(Asterisk(db.tbl_staff)).
                                   From(db.tbl_staff).
                                   Where(instance.field == 1 || instance.Property == 20 || instance.Method() == 30));

            var datas = _connection.Query(sql).ToList();

            Assert.IsTrue(0 < datas.Count);
            AssertEx.AreEqual(sql, _connection,
                              @"SELECT *
FROM tbl_staff
WHERE @field = @p_0 OR @Property = @p_1 OR @p_2 = @p_3",
                              new Params()
            {
                { "@field", 1 },
                { "@Property", 2 },
                { "@p_0", 1 },
                { "@p_1", 20 },
                { "@p_2", 3 },
                { "@p_3", 30 },
            });
        }
コード例 #2
0
        public void Test_Nest_Expression()
        {
            var condition = new ValuesInstance();

            var exp1 = Db <DB> .Sql(db => condition.field == 1 || condition.Property == 20 || condition.Method() == 30);

            int a    = 1;
            var exp2 = Db <DB> .Sql(db => exp1 && a == 1);

            var sql = Db <DB> .Sql(db =>
                                   Select(Asterisk(db.tbl_staff)).
                                   From(db.tbl_staff).
                                   Where(exp2));

            var datas = _connection.Query(sql).ToList();

            Assert.IsTrue(0 < datas.Count);
            AssertEx.AreEqual(sql, _connection,
                              @"SELECT *
FROM tbl_staff
WHERE (@field = @p_0 OR @Property = @p_1 OR @p_2 = @p_3) AND @a = @p_4",
                              new Params()
            {
                { "@field", 1 },
                { "@Property", 2 },
                { "@p_0", 1 },
                { "@p_1", 20 },
                { "@p_2", 3 },
                { "@p_3", 30 },
                { "@a", 1 },
                { "@p_4", 1 },
            });
        }