Пример #1
0
        public void TestMethod_Row2Object2()
        {
            BizBO   bizBo = TransactionAOP.newInstance(typeof(BizBO)) as BizBO;
            DataRow dr    = bizBo.add2();
            MyCity2 city  = DBUtil.Row2Object <MyCity2>(dr);

            Assert.AreEqual(0, city.city_id1, "id ");
            Assert.AreEqual("A Corua (La Corua)", city.city, "cityname");
            Assert.AreEqual(87, city.country_id, "countryid");
        }
Пример #2
0
        /// <summary>
        /// 通过物理主键,从数据库中,查找记录,并根据Mapping信息,把数据封装成对象返回
        /// </summary>
        /// <param name="tableObject">含Mapping信息的对象</param>
        /// <returns>具体对象</returns>
        public T Get <T>(T tableObject) where T : new()
        {
            Object2Get obj2Get = getObject2Get();

            obj2Get.parse(tableObject);
            DataRow row = this.Get(obj2Get.AsSql(), obj2Get.GetSqlParameterNames(), obj2Get.GetSqlParameterValues());

            T result = default(T);

            if (row == null)
            {
                return(result);
            }
            else
            {
                return(DBUtil.Row2Object <T>(row));
            }
        }
Пример #3
0
        public void TestMethod_Row2Object()
        {
            BizBO   bizBo = TransactionAOP.newInstance(typeof(BizBO)) as BizBO;
            DataRow dr    = bizBo.add2();
            MyCity  city  = DBUtil.Row2Object <MyCity>(dr);

            Assert.AreEqual(1, city.city_id, "id is 1");
            //BizBO bizBo = TransactionAOP.newInstance(typeof(BizBO)) as BizBO;
            //DataRow dr = bizBo.add2();
            //TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks); //获取当前时间的刻度数
            //for (int i = 0; i < 3000; i++)
            //{
            //    MyCity city = DBUtil.Row2Object<MyCity>(dr);
            //}
            //TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
            //TimeSpan ts = ts2.Subtract(ts1).Duration(); //时间差的绝对值
            //string spanTotalSeconds = ts.TotalSeconds.ToString(); //执行时间的总秒数
            //Console.WriteLine("执行时间总秒数:" + spanTotalSeconds);
        }
Пример #4
0
        /// <summary>
        /// 通过逻辑主键,从数据库中,查找记录,并根据Mapping信息,把数据封装成对象返回
        /// </summary>
        /// <param name="tableObject">含Mapping信息的对象</param>
        /// <returns>具体对象</returns>
        public T Find <T>(T tableObject) where T : new()
        {
            Object2Find Obj2Find = getObject2Find();

            obj2Find.parse(tableObject);
            DataRow row = this.Find(Obj2Find.AsSql(), Obj2Find.GetSqlParameterNames(), Obj2Find.GetSqlParameterValues());



            T result = default(T);

            if (row == null)
            {
                return(result);
            }
            else
            {
                return(DBUtil.Row2Object <T>(row));
            }
        }