当前位置:数据库 > SQLServer >>

查询大数据表的效率对比:Linq to SQL、Entity Framework、企业库存储过程、ADO.Net

最近因为要开发大数据量网站,特作比较。
 
 
Linq to SQL 查询 记录数:399997
Linq to SQL 查询 Milliseconds:1910
视图查询 记录数:399997
视图查询 Milliseconds:3435
Entity Framework 查询 记录数:400000
Entity Framework 查询 Milliseconds:4049
企业库存储过程 to DataReader 记录数:399997
企业库存储过程 to DataReader Milliseconds:321
企业库存储过程 to DataSet 记录数:399997
企业库存储过程 to DataSet Milliseconds:2807
ADO.Net存储过程 to SqlDataReader 记录数:399997
ADO.Net存储过程 to SqlDataReader Milliseconds:306
企业库SQL语句直接查询 to DataSet 记录数:399997
企业库SQL语句直接查询 to DataSet Milliseconds:3015
企业库SQL语句直接查询 to DataReader 记录数:399997
企业库SQL语句直接查询 to DataReader Milliseconds:367
 
第二次执行:
 
 

 
代码:
 
  View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Diagnostics;
using System.Data.Objects;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            SeewoECP.Model.School model = new SeewoECP.Model.School();
            model.ID = "1";
            model.Name = "test";
            model.Country = "test";
            model.Province = "test";
            model.City = "test";
            model.Address = "test";
            model.ZipCode = "test";
            model.Phone = "test";
            model.IsApproved = true;

            int repeatTimes = 1;

            Stopwatch sw3 = new Stopwatch();
            sw3.Start();

            for (int i = 0; i < repeatTimes; i++)
            {
                DataClasses1DataContext dc = new DataClasses1DataContext();
               
                //IEnumerable<School> schs = dc.ExecuteQuery<School>("Select * from School");
                //System.Data.Linq.Table<School> schools = dc.Schools;
                List<School> schools = dc.Schools.ToList();
                int count = 0;
                foreach (School sc in schools)
                {
                    count++;
                }
                //List<School> schs = schools.ToList();
                Response.Write("<br>Linq to SQL 查询 记录数:" + schools.Count().ToString());

            }

            sw3.Stop();
            Response.Write("<br>Linq to SQL 查询 Milliseconds:<font color='#FF0000'>" + sw3.ElapsedMilliseconds+"</font>");  
           
            Stopwatch sw2 = new Stopwatch();
            sw2.Start();
            DataSet dr = new DataSet();
            for (int i = 0; i < repeatTimes; i++)
            {
                 dr = selectView();
            }
            Response.Write("<br>视图查询 记录数:" + dr.Tables[0].Rows.Count);

            sw2.Stop();
            Response.Write("<br>视图查询 Milliseconds:<font color='#FF0000'>" + sw2.ElapsedMilliseconds + "</font>");

            Stopwatch sw4 = new Stopwatch();
            sw4.Start();

            for (int i = 0; i < repeatTimes; i++)
            {
                ECPDBEntities1 ecp = new ECPDBEntities1();
                ObjectSet<ClassGroup> classGroup = ecp.ClassGroup;
                //List<ClassGroup> classGroup = ecp.ClassGroup.ToList();
                //List<ClassGroup> classGroup =
                //from s in ecp.ClassGroup where s.id < 10 select s.name;

                //ClassGroup cg = classGroup.Single(s => s.ID == "1");
                int count = 0;
                foreach (

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,