コード例 #1
0
ファイル: WhereSample.cs プロジェクト: phuongvobys/DapperAid
        public void Tutorial()
        {
            int?val1 = 100;  // (bound to @IntCol)

            Select <T>(t => t.IntCol == val1);
            Select <T>(t => t.IntCol != val1);
            Select <T>(t => t.IntCol < val1);
            Select <T>(t => t.IntCol > val1);
            Select <T>(t => t.IntCol <= val1);
            Select <T>(t => t.IntCol >= val1);

            int?val2 = null;

            Select <T>(t => t.IntCol == val2);
            Select <T>(t => t.IntCol != val2);

            Select <T>(t => t.IntCol == t.OtherCol);

            string[] inValues = { "111", "222", "333" }; // (bound to @TextCol)
            Select <T>(t => t.TextCol == ToSql.In(inValues));
            Select <T>(t => t.TextCol != ToSql.In(inValues));
            Select <T>(t => t.IntCol != ToSql.In(new[] { 1, 2, 3 }));

            string likeValue = "%test%"; // (bound to @TextCol)

            Select <T>(t => t.TextCol == ToSql.Like(likeValue));
            Select <T>(t => t.TextCol != ToSql.Like(likeValue));

            int b1 = 1;  // (bound to @IntCol)
            int b2 = 99; // (bound to @P01)

            Select <T>(t => t.IntCol == ToSql.Between(b1, b2));

            Select <T>(t => t.TextCol == "111" && t.IntCol < 200);
            Select <T>(t => t.TextCol == "111" || t.IntCol < 200);
            Select <T>(t => !(t.TextCol == "111" || t.IntCol < 200));

            string text1 = "111";
            string text2 = null;

            Select <T>(t => text1 == null || t.TextCol == text1);
            Select <T>(t => text1 != null && t.TextCol == text1);
            Select <T>(t => text2 == null || t.TextCol == text2);
            Select <T>(t => text2 != null && t.TextCol == text2);

            Select <T>(t => t.TextCol == ToSql.In <string>("select text from otherTable where..."));
            Select <T>(t => t.IntCol == ToSql.In <int?>("select text from otherTable where..."));

            Select <T>(t => ToSql.Eval("exists(select * from otherTable where...)"));
        }
コード例 #2
0
ファイル: Sample1.cs プロジェクト: phuongvobys/DapperAid
        public void ToSqlTest()
        {
            QueryBuilder.DefaultInstance = new QueryBuilder.SQLite();

            using (IDbConnection connection = GetSqliteDbConnection())
            {
                var createTableSql = DDLAttribute.GenerateCreateSQL <Member>();
                connection.Execute(createTableSql);

                var list1 = connection.Select <Member>(r =>
                                                       (r.Name == ToSql.In(new[] { "A", "B" }) ||
                                                        r.Name != ToSql.Like("%TEST%") ||
                                                        r.Name == ToSql.Between("1", "5") ||
                                                        DateTime.Now < r.CreatedAt));
            }
        }