Example #1
0
        /// <summary>
        /// 获取列表数据
        /// </summary>
        /// <param name="cp">where条件,没有可传人null</param>
        /// <param name="orders">排序字段对象</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns></returns>
        public static List <T> GetList <T>(OQLCompare cp, OQLOrder orders, int pageSize, int pageIndex) where T : EntityBase, ILongID, new()
        {
            T   m = new T();
            OQL q = new OQL(m);

            if ((object)cp != null)
            {
                if ((object)orders != null)
                {
                    q.Select().Where(cp).OrderBy(orders);
                }
                else
                {
                    q.Select().Where(cp);
                }
            }
            else
            {
                if ((object)orders != null)
                {
                    q.Select().OrderBy(orders);
                }
                else
                {
                    q.Select();
                }
            }
            q.PageWithAllRecordCount = GetRecordCounts <T>(cp);
            if (pageSize > 0 && pageIndex > 0 && q.PageWithAllRecordCount > 0)
            {
                q.Limit(pageSize, pageIndex);
            }

            return(EntityQuery <T> .QueryList(q));
        }
Example #2
0
        /// <summary>
        /// 获取符合条件的实体对象列表 OQLCompareFunc
        /// </summary>
        /// <param name="cp">where条件,没有可传人null</param>
        /// <param name="orders">排序字段对象</param>
        /// <returns></returns>
        public static List <T> GetAllList <T>(OQLCompareFunc <T> cp, OQLOrder orders) where T : EntityBase, ILongID, new()
        {
            T   m = new T();
            OQL q = new OQL(m);

            if ((object)cp != null)
            {
                if ((object)orders != null)
                {
                    q.Select().Where(cp).OrderBy(orders);
                }
                else
                {
                    q.Select().Where(cp);
                }
            }
            else
            {
                if ((object)orders != null)
                {
                    q.Select().OrderBy(orders);
                }
                else
                {
                    q.Select();
                }
            }
            q.PageWithAllRecordCount = GetRecordCounts <T>(cp);
            string s = q.PrintParameterInfo();

            return(EntityQuery <T> .QueryList(q));
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("====**************** PDF.NET SOD 控制台测试程序 **************====");
            Assembly coreAss = Assembly.GetAssembly(typeof(AdoHelper));//获得引用程序集

            Console.WriteLine("框架核心程序集 PWMIS.Core Version:{0}", coreAss.GetName().Version.ToString());
            Console.WriteLine();
            Console.WriteLine("  应用程序配置文件默认的数据库配置信息:\r\n  当前使用的数据库类型是:{0}\r\n  连接字符串为:{1}\r\n  请确保数据库服务器和数据库是否有效且已经初始化过建表脚本(项目下的2个sql脚本文件),\r\n继续请回车,退出请输入字母 Q ."
                              , MyDB.Instance.CurrentDBMSType.ToString(), MyDB.Instance.ConnectionString);
            Console.WriteLine("=====Power by Bluedoctor,2015.2.8 http://www.pwmis.com/sqlmap ====");
            string read = Console.ReadLine();

            if (read.ToUpper() == "Q")
            {
                return;
            }

            //写入10000条日志,有缓存,可能不会写完
            Console.WriteLine("测试日志写入10000 条信息...");
            CommandLog loger = new CommandLog();

            for (int t = 0; t <= 100; t++)
            {
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(WriteLog));
                thread.Name = "thread" + t;
                thread.Start(loger);
            }

            loger.Flush();
            Console.WriteLine("按任意键继续");
            Console.ReadLine();

            EntityUser  etu = new EntityUser();
            ITable_User itu = etu.AsEntity();
            DateTime    dtt = itu.Birthday;



            //测试 AdoHelper的并发能力
            //for (int i = 0; i < 100; i++)
            //{
            //    System.Threading.Thread t = new System.Threading.Thread(
            //        new System.Threading.ParameterizedThreadStart(TestDataSetAndOQL));
            //    t.Name = "thread "+i;
            //    t.Start();

            //}

            //测试生成列的脚本
            EntityCommand ecmd         = new EntityCommand(new Table_User(), new SqlServer());
            string        table_script = ecmd.CreateTableCommand;

            Console.Write("1,测试 OpenSession 长连接数据库访问...");
            TestDataSetAndOQL(null);
            Console.WriteLine("OK");
            //
            Console.WriteLine("2,测试OQL 转SQL...");
            RoadTeam.Model.CS.TbCsEvent CsEvent = new RoadTeam.Model.CS.TbCsEvent();
            CsEvent.EventID = 1;
            OQL oql = OQL.From(CsEvent)
                      .Select(CsEvent.EventCheck, CsEvent.EventCheckInfo, CsEvent.EventCheckor, CsEvent.EventCheckTime)
                      .Where(CsEvent.EventID)
                      .END;

            Console.WriteLine(oql.ToString());
            Console.WriteLine("-----------------------");

            RoadTeam.Model.CS.TbCsEvent CsEvent2 = new RoadTeam.Model.CS.TbCsEvent();
            CsEvent.EventID = 1;
            OQL oql2 = OQL.From(CsEvent2)
                       .Select(true, CsEvent2.EventCheck, CsEvent2.EventCheckInfo, CsEvent2.EventCheckor, CsEvent2.EventCheckTime)
                       .Where(CsEvent2.EventID)
                       .END;

            Console.WriteLine(oql2.ToString());
            Console.WriteLine("-----------------------");
            Console.WriteLine("OK");
            //
            Console.Write("3,测试实体类动态增加虚拟属性...");
            UserModels um1 = new UserModels();

            um1.AddPropertyName("TestName");
            um1["TestName"] = 123;
            int testi = (int)um1["TestName"];

            um1["TestName"] = "abc";
            string teststr = (string)um1["TestName"];

            Console.WriteLine("OK");
            //
            Console.Write("4,测试缓存...");
            var cache = PWMIS.Core.MemoryCache <EntityBase> .Default;

            cache.Add("UserModels", um1);
            var cacheData = cache.Get("UserModels");

            cache.Remove("UserModels");
            Console.WriteLine("OK");
            //
            Console.Write("5,测试自动创建实体类数据库表...");
            AutoCreateEntityTable <LT_Users>();
            AutoCreateEntityTable <LT_UserRoles>();
            Console.WriteLine("OK");

            Console.WriteLine("------------测试暂时停止,回车继续运行------");
            Console.ReadLine();
            //return;

            Console.Write("6,测试实体类的外键查询...");
            TestEntityFK();
            Console.WriteLine("OK");
            Console.Write("7,测试实体类批量插入...");
            OqlInTest();
            Console.WriteLine("OK");

            Console.WriteLine("8,测试SOD POCO实体类性能...");
            Console.WriteLine("SELECT top 100000 UID,Sex,Height,Birthday,Name FROM Table_User");
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("-------------Testt No.{0}----------------", i + 1);
                TestPocoQuery();
            }
            Console.WriteLine("--------OK---------------");

            Console.Write("9,测试OQL IN 子查询...");
            TestInChild();
            Console.WriteLine("OK");
            //TestFun(1, 2, 3);

            Console.WriteLine("10,测试泛型 OQL --GOQL");
            TestGOQL();
            Console.WriteLine("OK");

            Console.WriteLine("11,测试OQL 批量更新(带条件更新)...");
            UpdateTest();
            Console.WriteLine("OK");

            Console.WriteLine("12,测试批量数据插入性能....");
            //InsertTest();



            Console.WriteLine("13,OQL 自连接...");
            OqlJoinTest();
            //
            Console.Write("14,根据接口类型,自动创建实体类测试...");
            TestDynamicEntity();
            Console.WriteLine("OK");

            //
            Console.WriteLine("15,Sql 格式化查询测试( SOD 微型ORM功能)...");
            AdoHelper dbLocal = new SqlServer();

            dbLocal.ConnectionString = MyDB.Instance.ConnectionString;
            //DataSet ds = dbLocal.ExecuteDataSet("SELECT * FROM Table_User WHERE UID={0} AND Height>={1:5.2}", 1, 1.80M);

            /*
             * 下面的写法过时
             * var dataList = dbLocal.GetList(reader =>
             * {
             *  return new
             *  {
             *      UID=reader.GetInt32(0),
             *      Name=reader.GetString(1)
             *  };
             * }, "SELECT UID,Name FROM Table_User WHERE Sex={0} And Height>={0:5.2}",1, 1.60);
             */
            var dataList = dbLocal.ExecuteMapper("SELECT UID,Name FROM Table_User WHERE Sex={0} And Height>={1:5.2}", 1, 1.60)
                           .MapToList(reader => new
            {
                UID  = reader.GetInt32(0),
                Name = reader.GetString(1)
            });

            Console.WriteLine("OK");

            //
            Console.Write("16,测试属性拷贝...");
            V_UserModels vum = new V_UserModels();

            vum.BIGTEAM_ID   = 123;//可空属性,如果目标对象不是的话,无法拷贝
            vum.REGION_ID    = 456;
            vum.SMALLTEAM_ID = 789;

            UserModels um = vum.CopyTo <UserModels>();

            Console.WriteLine("OK");

            //
            Console.Write("17,测试【自定义查询】的实体类...");
            UserPropertyView up = new UserPropertyView();
            OQL      q11        = new OQL(up);
            OQLOrder order      = new OQLOrder(q11);

            q11.Select()
            .Where(q11.Condition.AND(up.PropertyName, "=", "总成绩").AND(up.PropertyValue, ">", 1000))
            .OrderBy(order.Asc(up.UID));
            AdoHelper db11   = MyDB.GetDBHelperByConnectionName("local");
            var       result = EntityQuery <UserPropertyView> .QueryList(q11, db11);

            //下面2行不是必须
            q11.Dispose();
            Console.WriteLine("OK");

            //EntityContainer ec = new EntityContainer(q11);
            //var ecResult = ec.MapToList(() => {
            //    return new { AAA = ec.GetItemValue<int>(0), BBB = ec.GetItemValue<string>(1) };
            //});

            /////////////////////////////////////////////////////
            Console.WriteLine("18,测试实体类【自动保存】数据...");

            TestAutoSave();

            /////////////////测试事务////////////////////////////////////
            Console.WriteLine("19,测试测试事务...");
            TestTransaction();
            TestTransaction2();
            Console.WriteLine("事务测试完成!");
            Console.WriteLine("-------PDF.NET SOD 测试全部完成-------");

            Console.ReadLine();
        }
Example #4
0
 void OQLOrder(OQLOrder p, Users user)
 {
     p.Desc(user.UserName).Asc(user.ID);
 }