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