Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework queries speed

Recently I started to learning Entity Framework.

First question made in my mind is:

When we want to use LINQ to fetching data in EF, every query like this:

var a = from p in contacts select p.name ;

will be converts to SQL commands like this :

select name from contacts
  1. does this converting repeat every time that we are querying?
  2. I heard that stored procedures are cached in database, does this event happens in LINQ queries in Entity Framework ?

And at last is my question clear?

like image 973
Shahin Avatar asked Mar 28 '11 12:03

Shahin


People also ask

Is Entity Framework faster than SQL query?

Entity Framework very slow compared to SQL Query.

Why is Entity Framework so slow?

Databases grow alongside our clients' business. But since the load of systems increases over time, it could cause the entity framework slow performance. Another reason for the performance degradation is a change in business rules.


2 Answers

I think linq query is converted each time you want to execute it. To improve performance you can use compiled queries.

like image 188
Ladislav Mrnka Avatar answered Nov 15 '22 09:11

Ladislav Mrnka


There are all sorts of optimizations being made, both in the linq expression caching and what SQL server chooses to cache, the only way is to measure your performance speed and memory consumption

To see what SQL is created you can use http://efprof.com/ which I've found quite good. You can get some of this info through SQL profiler, it's just a lot more work.

like image 26
Adam Straughan Avatar answered Nov 15 '22 10:11

Adam Straughan