/// <summary>
        /// Code was not auto generate this method
        /// </summary>
        /// <param name="customersGen"></param>
        /// <returns></returns>
        public int InsertCustomersGen(CustomersGen customersGen)
        {
            var returnobj = baseDao.Insert(customersGen);

            if (returnobj != null)
            {
                return(Convert.ToInt32(returnobj));
            }
            return(0);
        }
        public void TestUpdateCustomersGen()
        {
            CustomersGen customersGen = new CustomersGen()
            {
                CustomerID = "11", CompanyName = "UTChanged"
            };
            int ret = customersGenDao.UpdateCustomersGen(customersGen);

            Assert.IsTrue(ret > 0);
        }
Esempio n. 3
0
        /// <summary>
        /// WriteTest
        /// </summary>
        /// <param name="repeatTime"></param>
        /// <returns></returns>
        public long WriteTest(int repeatTime)
        {
            return(Utility.PerformanceWatch(
                       () =>
            {
                for (int i = 0; i < repeatTime; i++)
                {
                    var customer = new CustomersGen
                    {
                        CompanyName = "Newcvompanyname",
                        ContactName = "ccc",
                        Address = "asdcadsdws",
                        ContactTitle = "adsdf",
                        City = "ku2na",
                        Country = "chi2na",
                        Phone = "231",
                        PostalCode = "234",
                        Region = "ASIA",
                        CustomerID = "9011"
                    };

                    int customerIdFromDb = customersGenDao.InsertCustomersGen(customer);

                    var catagore = new CategoriesGen()
                    {
                        CategoryName = "xdf", Description = "asfb"
                    };
                    int categoryIDfromDb = categoriesGenDao.InsertCategoriesGen(
                        catagore
                        );

                    var product = new ProductsGen
                    {
                        ProductName = "Blue Widget234",
                        UnitPrice = 35.56M,
                        CategoryID = categoryIDfromDb
                    };

                    //Insert
                    product.ProductID = productsGenDao.InsertProductsGen(product
                                                                         );

                    product.ProductName = "ProductNameChange";
                    //Update
                    productsGenDao.UpdateProductsGen(product);

                    //Delete
                    productsGenDao.DeleteProductsGen(product);
                    customersGenDao.DeleteCustomersGen(customer);
                    categoriesGenDao.DeleteCategoriesGen(catagore);
                }
            }));
        }
        //特别注意,如果是可空类型,建议以如下方式使用:
        // var data = reader["field"];
        // entity.stringData = data == null ? data : data.ToString();
        //如需要手工映射,请反注释如下代码,并注意转换类型

        /*
         * /// <summary>
         * /// 手工映射,建议使用1.2.0.5版本以上的VisitDataReader
         * /// </summary>
         * /// <returns>结果</returns>
         * public CustomersGen OrmByHand(string sql)
         * {
         *  try
         *  {
         *      return baseDao.VisitDataReader<CustomersGen>(sql, (reader) =>
         *      {
         *          CustomersGen entity = new CustomersGen();
         *                              if(reader.Read())
         *                              {
         *              entity.Address = reader["Address"];
         *              entity.City = reader["City"];
         *              entity.CompanyName = reader["CompanyName"];
         *              entity.ContactName = reader["ContactName"];
         *              entity.ContactTitle = reader["ContactTitle"];
         *              entity.Country = reader["Country"];
         *              entity.CustomerID = reader["CustomerID"];
         *              entity.Fax = reader["Fax"];
         *              entity.Phone = reader["Phone"];
         *              entity.PostalCode = reader["PostalCode"];
         *              entity.Region = reader["Region"];
         *          }
         *          return entity;
         *      });
         *
         *      //CustomersGen entity = new CustomersGen();
         *      //using(var reader = baseDao.SelectDataReader(sql))
         *      //{
         *                              //if(reader.Read())
         *                              //{
         *              //entity.Address = reader["Address"];
         *              //entity.City = reader["City"];
         *              //entity.CompanyName = reader["CompanyName"];
         *              //entity.ContactName = reader["ContactName"];
         *              //entity.ContactTitle = reader["ContactTitle"];
         *              //entity.Country = reader["Country"];
         *              //entity.CustomerID = reader["CustomerID"];
         *              //entity.Fax = reader["Fax"];
         *              //entity.Phone = reader["Phone"];
         *              //entity.PostalCode = reader["PostalCode"];
         *              //entity.Region = reader["Region"];
         *              //}
         *      //}
         *      //return entity;
         *  }
         *  catch (Exception ex)
         *  {
         *      throw new DalException("调用CustomersGenDao时,访问OrmByHand时出错", ex);
         *  }
         * }
         */
        /// <summary>
        /// 修改CustomersGen
        /// </summary>
        /// <param name="customersGen">CustomersGen实体对象</param>
        /// <returns>状态代码</returns>
        public int UpdateCustomersGen(CustomersGen customersGen)
        {
            try
            {
                Object result  = baseDao.Update <CustomersGen>(customersGen);
                int    iReturn = Convert.ToInt32(result);

                return(iReturn);
            }
            catch (Exception ex)
            {
                throw new DalException("调用CustomersGen时,访问Update时出错", ex);
            }
        }
        /// <summary>
        ///  检索CustomersGen,带翻页
        /// </summary>
        /// <param name="obj">CustomersGen实体对象检索条件</param>
        /// <param name="pagesize">每页记录数</param>
        /// <param name="pageNo">页码</param>
        /// <returns>检索结果</returns>
        public IList <CustomersGen> GetListByPage(CustomersGen obj, int pagesize, int pageNo)
        {
            try
            {
                StringBuilder sbSql = new StringBuilder(200);

                sbSql.Append(@"select Address, City, CompanyName, ContactName, ContactTitle, Country, CustomerID, Fax, Phone, PostalCode, Region from Customers (nolock) ");
                sbSql.Append(" order by CustomerID desc ");
                sbSql.Append(string.Format("OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", (pageNo - 1) * pagesize, pagesize));
                IList <CustomersGen> list = baseDao.SelectList <CustomersGen>(sbSql.ToString());
                return(list);
            }
            catch (Exception ex)
            {
                throw new DalException("调用CustomersGenDao时,访问GetListByPage时出错", ex);
            }
        }
        public void TestInsertCustomersGen()
        {
            var customersGen = new CustomersGen
            {
                CompanyName  = "Newcvompanyname",
                ContactName  = "ccc",
                Address      = "asdcadsdws",
                ContactTitle = "adsdf",
                City         = "ku2na",
                Country      = "chi2na",
                Phone        = "231",
                PostalCode   = "234",
                Region       = "ASIA",
                CustomerID   = "9012"
            };

            int ret = customersGenDao.InsertCustomersGen(customersGen);

            Assert.IsTrue(ret > 0);
        }