Entity Framework knife initial test

Source: Internet
Author: User

This entity framework has been around for a long time, and I accidentally saw an article in the garden two days ago.Article(A year ago) said: Microsoft will discard the two frameworks. At the same time, it found that Microsoft uses LINQ to entity in the help of the msdn Entity Framework to help existing LINQ to SQL developers migrate to the Entity Framework, finally, after writing a bunch of LINQ to SQL statements, I can't help the temptation of Entity Framework. I tried it. To tell the truth, I don't feel very good. This is just a test. I am referring to the Entity Framework Learning Guide, the following is the result of my simple test. I don't know much about Entity Framework, and I only read two chapters about Entity Framework Learning Guide, everyone has bricks, eggs, or something in their hands. Don't waste it.

 

1. Preparations

1.1 environment: Windows Server 2003, Visual Studio 2008 SP1, SQL 2005 Express

1.2 The database is the northwind database downloaded according to the prompts in the Entity Framework Learning Guide.

 

2. TestCode, Extremely simple

2.1,

1 VaR DB =   New Northwindentities ();
2 // Record Start Time
3 Datetime starttime = Datetime. now;
4 VaR employees = From EMP In DB. Employees select EMP;
5 Foreach (VAR E In Employees)
6 {
7 Console. writeline ( " Firstname: {0} " , E. firstname );
8 }
9 // Record End Time
10 Datetime endtime = Datetime. now;
11 Timespan TS = Endtime. Subtract (starttime). duration ();
12 Console. foregroundcolor = Lelecolor. Red;
13 Console. writeline ( " Time: {0} " , Ts. totalmilliseconds );
14 Console. foregroundcolor = Lelecolor. Gray;

2.2 note that the above Code simply creates an Entity Framework object, calls its employees object, and obtains all the data in the Employees table in the database (in fact, there are only a few rows ), iterate and output the firstjname of an employee.

2.3 added a datetime object to record the time from obtaining the employee object to the output. This is all the code.

2.4. The first time the data was loaded, it took 968.75 milliseconds. Only nine rows of data in the partition area were used. (Of course, I do not know whether other associated table data is loaded here)

 

The 2.5 re-loading result takes 15.625 ms and 0 ms. The 0 Ms occurs because there is no interval between loading from the last load, and the 15.625 MS is because the loading interval is three seconds after the last load.

3. Change the code segment and try again.

3.1 this time, I started timing from the creation of the Entity Framework object. Please pay attention to the start position of the recording of the red datetime object.

1 // Record Start Time
2 Datetime starttime = Datetime. now;
3 VaR DB =   New Northwindentities ();
4 VaR employees = From EMP In DB. Employees select EMP;
5 Foreach (VAR E In Employees)
6 {
7Console. writeline ("Firstname: {0}", E. firstname );
8}
9 // Record End Time
10 Datetime endtime = Datetime. now;
11 Timespan TS = Endtime. Subtract (starttime). duration ();
12 Console. foregroundcolor = Lelecolor. Red;
13 Console. writeline ( " Time: {0} " , Ts. totalmilliseconds );
14 Console. foregroundcolor = Lelecolor. Gray;

 

3.2. The first loading of the test results took 100 milliseconds longer than the last test. When you wait on the console, you can truly feel the delay, check the result.

 

3.2 The re-loading results are the same as those in the first test code. Here I will not map any more.

4. What are the results? I don't dare to draw conclusions. Leave it for everyone.

4.1,Because I have just started to understand the Entity Framework, andEntity Framework Learning GuideI also read two chapters, and I am not good at English. There may be many differences in understanding.

Certificate --------------------------------------------------------------------------------------------------------------------------------------------------------

 

Welcome to repost, but please indicate the source-lsotcode blog (http://www.cnblogs.com/viter )!

You are welcome to make a brick!

 

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.