Example #1
0
        public Result InsertHouseInfos()
        {
            Result ret = new Result();

            using (var smartConn = new SmartWorldEntities())
            {
                for (int i = 1; i <= 3; i++)
                {
                    D_House r = new D_House()
                    {
                        Id         = Guid.NewGuid(),
                        Address    = "成都",
                        Floor      = i,
                        HouseCode  = DateTime.Now.Date.ToString(),
                        HouseTitle = "测试" + i,
                        Price      = 100,
                        Remark     = "说明",
                        Property   = (int)PropertyType.私证,
                        CreateDate = DateTime.Now,
                        HouseType  = (int)HouseType.出租,
                        YearPrice  = 1000,
                        IsDelete   = false
                    };

                    //List<int> GetListEnum = PropertyType.私证.GetListEnum<int>(typeof(int));
                    //List<string> GetListEnum2 = PropertyType.私证.GetListEnum<string>(typeof(string));

                    smartConn.D_House.Add(r);
                }
                ret.Success = smartConn.SaveChanges() > 0;
            }
            return(ret);
        }
Example #2
0
        public string GetTimeTest()
        {
            List <D_House> list1 = new List <D_House>();
            List <D_House> list2 = new List <D_House>();
            List <D_House> list3 = new List <D_House>();

            using (var smartConn = new SmartWorldEntities())
            {
                Stopwatch watch1 = new Stopwatch();
                watch1.Start();
                for (int i = 1; i <= 2000; i++)
                {
                    D_House r = new D_House()
                    {
                        Id         = Guid.NewGuid(),
                        Address    = "成都",
                        Floor      = i,
                        HouseCode  = DateTime.Now.Date.ToString(),
                        HouseTitle = "测试" + i,
                        Price      = 100,
                        Remark     = "说明",
                        Property   = (int)PropertyType.私证,
                        CreateDate = DateTime.Now,
                        HouseType  = (int)HouseType.出租,
                        YearPrice  = 1000,
                        IsDelete   = false
                    };
                    list1.Add(r);
                }
                smartConn.D_House.AddRange(list1);

                watch1.Stop();


                Stopwatch watch2 = new Stopwatch();
                watch2.Start();
                for (int i = 1; i <= 2000; i++)
                {
                    D_House r = new D_House()
                    {
                        Id         = Guid.NewGuid(),
                        Address    = "成都",
                        Floor      = i,
                        HouseCode  = DateTime.Now.Date.ToString(),
                        HouseTitle = "测试" + i,
                        Price      = 100,
                        Remark     = "说明",
                        Property   = (int)PropertyType.私证,
                        CreateDate = DateTime.Now,
                        HouseType  = (int)HouseType.出租,
                        YearPrice  = 1000,
                        IsDelete   = false
                    };
                    list2.Add(r);
                }
                smartConn.BulkInsert(list2);

                smartConn.SaveChanges();
                watch2.Stop();

                Stopwatch watch3 = new Stopwatch();
                //watch3.Start();
                //for (int i = 1; i <= 2000; i++)
                //{
                //    D_House r = new D_House()
                //    {
                //        Id = Guid.NewGuid(),
                //        Address = "成都",
                //        Floor = i,
                //        HouseCode = DateTime.Now.Date.ToString(),
                //        HouseTitle = "测试" + i,
                //        Price = 100,
                //        Remark = "说明",
                //        Property = (int)PropertyType.私证,
                //        CreateDate = DateTime.Now,
                //        HouseType = (int)HouseType.出租,
                //        YearPrice = 1000,
                //        IsDelete = false
                //    };
                //    smartConn.D_House.Add(r);
                //}
                //smartConn.SaveChanges();
                watch3.Stop();

                string ret = string.Format(@" AddRange:{0};
                                        BulkInsert:{1};
                                        先添加后保存:{2};", watch1.Elapsed, watch2.Elapsed, watch3.Elapsed);
                return(ret);
            }
        }