Comparison of Ado.net Entity Framework query performance

Source: Internet
Author: User

About Ado.net Entity Framework Performance Comparison There's a lot on the web, here I'm just a preliminary introduction the Ado.net Entity Framework uses different methods to query for different performance of data

Part I: Querying a single entity repeatedly

First: Linq to Entitiess

The code is as follows:

static void Main(string[] args)
         {
             DateTime time1;
             DateTime time2;
             time1 = DateTime.Now;
             NorthwindEntities context = new  NorthwindEntities();
             for (int i = 0; i < 1000; i++)
             {
                 var data = (from c in  context.Customers where c.CustomerID == "ALFKI" select  c).FirstOrDefault();
                 string addr = data.Address;
             }
             time2 = DateTime.Now;
             Console.WriteLine((time2-time1).ToString ());
         }

Query usage time is about 6.2 seconds

Second: Using entity SQL

static void Main(string[] args)
         {
             DateTime time1;
             DateTime time2;
             time1 = DateTime.Now;
             NorthwindEntities context = new  NorthwindEntities();
             for (int i = 0; i < 1000; i++)
             {
                 var data =  context.Customers.Where("it.CustomerID=@Id", new  System.Data.Objects.ObjectParameter("Id", "ALFKI")).FirstOrDefault ();
                 string addr = data.Address;
             }
             time2 = DateTime.Now;
             Console.WriteLine((time2-time1).ToString ());
         }

Query usage time is about 6.2 seconds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.