Example #1
0
        public void InsertTest()
        {
            //MongoCollection.Remove(new { },true);

            var times = 100000;

            var rd = new Random();

            var time = DateTime.Now;

            for (int i = 0; i < times; i++)
            {
                var customer = new Customer
                {
                    Name = "Test_" + i.ToString("00000000"),
                    Info = new CustomerInfo
                    {
                        Phone = "1590086" + rd.Next(1000, 9999).ToString(),
                        Address = "上海市南京西路1256号"
                    },
                    Orders = new List<Order>(new Order[] { new Order { ID = 11, Name = "order11", BuyTime = DateTime.Now }, new Order { ID = 12, Name = "order12", BuyTime = DateTime.Now } })
                };

                MongoCollection.Insert(customer);
            }

            Trace.WriteLine(string.Format("Insert {0} data cost:{1} s", times.ToString(), DateTime.Now.Subtract(time).TotalSeconds.ToString("0.000")));
        }
Example #2
0
File: Test.cs Project: laball/demo
        public void TestMethod1()
        {
            //MongoCollection.Remove(new { },true);

            var times = 100000;

            var rd = new Random();

            var time = DateTime.Now;

            for (int i = 0; i < times; i++)
            {
                var customer = new Customer
                {
                    Age = rd.Next(12, 60),
                    CreateOn = DateTime.Now,
                    Height = 150.00d + 100 * rd.NextDouble(),
                    Info = new CustomerInfo
                    {
                        Phone = "1590086" + rd.Next(1000, 9999).ToString(),
                        Address = "上海市南京西路1256号"
                    },
                    IsMail = rd.Next(0, 1) == 0 ? false : true,
                    Name = "Test_" + i.ToString("00000000"),
                    Orders = new List<Order>(new Order[] { new Order { ID = 11, Name = "order11", BuyTime = DateTime.Now }, new Order { ID = 12, Name = "order12", BuyTime = DateTime.Now } }),
                    Weight = 48.00f + 50f * (float)rd.NextDouble()
                };

                MongoCollection.InsertOne(customer);
            }

            Trace.WriteLine(string.Format("Insert {0} data cost:{1} s", times.ToString(), DateTime.Now.Subtract(time).TotalSeconds.ToString("0.000")));
        }