Beispiel #1
0
        static void OqlInTest()
        {
            LT_UserRoles roles = new LT_UserRoles()
            {
                NickName = "Role1"
            };
            LT_Users users = new LT_Users();
            OQL      qRole = OQL.From(roles).Select(roles.ID).Where(
                cmp => cmp.Comparer(roles.NickName, "like", "123%")
                ).END;

            OQL qUser = new OQL(users);

            qUser.Select().Where(qUser.Condition
                                 .AND(users.LastLoginTime, ">=", DateTime.Now.AddDays(-10))
                                 .NotIn(users.RoleID, qRole));
            Console.WriteLine("OQL to SQL:\r\n{0},\r\n{1}", qUser, qUser.PrintParameterInfo());
        }
Beispiel #2
0
        static void UpdateTest()
        {
            LT_Users userCmp = new LT_Users()
            {
                Authority = "admin", IsEnable = true, Remarks = "add"
            };
            // LT_Users userQ = new LT_Users();
            //OQLCompare cmp = new OQLCompare(userCmp);
            //OQL q = new OQL(userQ);
            OQL        q   = new OQL(userCmp);
            OQLCompare cmp = new OQLCompare(q);

            cmp = cmp.Comparer(userCmp.ID, "in", new int[] { 1, 2, 3 })
                  & cmp.Comparer(userCmp.LastLoginIP, "=", "127.0.0.1");
            //------分界线-------

            q.Update(userCmp.Authority, userCmp.IsEnable, userCmp.Remarks).Where(cmp);

            Console.WriteLine("update test:{0}\r\n{1}", q, q.PrintParameterInfo());
        }
Beispiel #3
0
        static void OqlJoinTest()
        {
            LT_UserRoles roles = new LT_UserRoles()
            {
                NickName = "Role1"
            };
            LT_UserRoles roles2 = new LT_UserRoles();
            OQL          q2     = OQL.From(roles)
                                  .Join(roles2).On(roles.ID, roles2.ID)
                                  .Select(roles.ID, roles2.RoleName)
                                  .Where(cmp => cmp.EqualValue(roles.NickName))
                                  .END;

            Console.WriteLine("OQL 自连接:{0}", q2);

            LT_Users users = new LT_Users();
            OQL      q     = OQL.From(users)
                             .Join(roles).On(users.RoleID, roles.ID)
                             .Select(
                users.ID,
                users.UserName,
                roles.ID,
                roles.RoleName
                )
                             .Where(
                cmp => cmp.EqualValue(roles.NickName)
                )
                             .END;

            Console.WriteLine("OQL to SQL:\r\n{0}", q);

            EntityContainer ec   = new EntityContainer(q);
            var             list = ec.Map <UserRoleDto>(u =>
            {
                u.UserID   = ec.GetItemValue <int>(0);
                u.UserName = ec.GetItemValue <string>(1);
                u.RolesID  = ec.GetItemValue <int>(2);
                u.RoleName = ec.GetItemValue <string>(3);
                return(u);
            });
        }