Пример #1
0
 /// <summary>
 /// 测试实体类的外键查询
 /// </summary>
 static void TestEntityFK()
 {
     LT_UserRoles roles = new LT_UserRoles()
     {
         RoleName = "admin"
     };
     OQL q = OQL.From(roles)
             .Select()
             .Where(roles.RoleName)
             .END;
     var list = EntityQuery <LT_UserRoles> .QueryListWithChild(q, MyDB.Instance);
 }
Пример #2
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());
        }
Пример #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);
            });
        }