views:

22

answers:

1

I have read a fair amount about pre-generated views in EF but not sure which scenarios you wouldn't use it. My understanding is it simply requires a little set-up in your project and that is the only hit. So you will therefore get a performance improvement on first access of queries, essentially for free.

If that is the case why would you not simply use it on every EF project?

Thanks

+1  A: 

From MSDN:

http://blogs.msdn.com/b/dmcat/archive/2010/04/21/isolating-performance-with-precompiled-pre-generated-views-in-the-entity-framework-4.aspx

Since the first execution of the query is where the performance gain is, leveraging pre-generated views in at least two cases will be of significant value: the warm up of a system and the execution of infrequently run queries. The use of less memory is also advantageous and is due to no longer having the overhead of keeping and creating the views.

Precompiled views improve the performance of queries the first time they are run. Subsequent executions gain no improvement because the query is then compiled. This means that the benefit of precompiling any given query is dependent on when and how often it is executed.

Dave Swersky
Thanks for the reply Dave, that article is a little confusing as it interchanges pre-generated views and pre-compiled queries. I am happy I understand the pros and cons of compiled queries, I am still not sure I get the pre generated views.
Jon Archway
I *think* precompiled views and queries are the same thing. The terms seem to be used interchangeably.
Dave Swersky
I was pretty sure they were different, but they are called pre-generated views and pre compiled queries. The former is what EF requires to access a database. The latter is specific to queries.
Jon Archway
@Dave, no, the're different. A view is a special case of a query. A query is any query you write or cause to be generated. A view is a query the EF generates internally.
Craig Stuntz
So do we have a view on when NOT using pre generated views would be an advantage?
Jon Archway
I take that as a no then? :-)
Jon Archway