protected void Page_Load(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代
            DNetTransaction transaction = new DNetTransaction();

            transaction.BeginTransaction();
            try
            {
                using (DNetContext db = new DNetContext())
                {
                    List <Author> authors = new List <Author>();
                    for (int i = 0; i <= 100; i++)
                    {
                        authors.Add(new Author {
                            AuthorName = "测试" + i.ToString(), Age = 20, IsValid = true
                        });
                    }
                    db.Add(authors);
                    transaction.Commit();
                }
            }
            catch
            {
                transaction.Rollback();
            }
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            Response.Write("执行时间:" + milliseconds + "毫秒");
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start(); //  开始监视代
            using (DNetContext db = new DNetContext())
            {
                var authorid = db.Add(new Author {
                    AuthorName = "张三", Age = 30, IsValid = true
                });
                db.Add(new Book {
                    BookName = "从入门到放弃", Price = 20.5, PublishDate = DateTime.Now, AuthorID = authorid
                });
            }
            stopwatch.Stop();                                   //  停止监视
            TimeSpan timespan     = stopwatch.Elapsed;          //  获取当前实例测量得出的总时间
            double   milliseconds = timespan.TotalMilliseconds; //  总毫秒数

            Response.Write("执行时间:" + milliseconds + "毫秒");
        }