Вопрос

I am using MVC3, .NET4.5, C#, EF5.0, MSSQL2008 R2

My web application can take between 30 and 60secs to warm up ie get through first page load. Following page loads are very quick.

I have done a little more analysis, using DotTrace.

I have discovered that some of my LINQ queries, particularly the .COUNT and .ANY() ones take a long time to execute first time ie:

 if (!Queryable.Any<RPRC_Product>((IQueryable<RPRC_Product>) this.db.Class.OfType<RPRC_Product>(), (Expression<Func<RPRC_Product, bool>>) (c => c.ReportId == (int?) myReportId)))

takes around 12 secs on first use.

Can you provide pointer how I can get these times down. I have heard about precompilers for EF queries.

I have a feeling the answer lies in using precompilation rather than altering this specific query.

Many thanks in advance

EDIT

Just read up on EF5's auto compile feature, so second time round compiled queries are in cache. So first time round, compilation is still required to intermediate EF language. Also read up on pregeneration of Views which may help generally as well?

Это было полезно?

Решение

It is exactly as you said - you do not have to worry about compiling queries - they are cached automatically by ef. Pregenerated Views might help you or may not. Automatic tools for scaffolding them generates not all views required and the missing ones still needs to be made at run time. When I developed my solutions and expected the same problem as you the only thing that helped me was to simplify a query. It turns out that if the first query to run is very complex and involves complicated joins then ef needs to generate many views to execute it. So I simplified the queries - instead of loading whole joined entities I loaded only ids (grouped , filtered out or whatever) and then when I needed to load single entities I loaded them by ids one by one. This allowed me to avoid long execution time of my first query.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top