2
votes

I have an Asp.Net MVC application built with .Net 4.0 and EF6. To improve performance of the application, I came across various posts and got to know that we must have compiled queries to drastically increase the performance of the application.

So I went on searching for compiled query and wrote my own as below:

public static Func<KEEntities, IQueryable<tblProperty>> GetProperties =
            CompiledQuery.Compile((KEEntities db) => 
            from property in db.tblProperties select property);

But that query above gives me an error saying Error There is no implicit reference conversion from 'KEApplication.Models.EntityModel.KEEntities' to 'System.Data.Entity.Core.Objects.ObjectContext'.

Again after going through few posts and especially This, by reading the answer there, I was disappointed to know that the compiled queries wasn't supported in .Net 4 and EF6. I also read that EF version > 4 provided automatic compilation of queries, but in my case I am not seeing any improvements, if it happened to. Are there any other possible ways to achieve functionality like compiled query for the above configurations?

Did you really ensure that perfomance hit is caused by not compiled queries? I can hardly believe this might have any serious difference compared to how much the actual database query takes. - Evk
I did not perform a deep check. I just optimized my whole application code with ReSharper and the only thing now remaining was Query optimization. Above all, I am taking LINQPad tool now to test the queries performance. - Guruprasad J Rao
If you cannot compile them - how would you compare compiled vs non-compiled version perfomance? Aside from that I bet that you might better spend your time optimizing queries itself (ensure all indexes are in place, ensure query plans are reasonable etc) :) - Evk
Yea! That is well being done.. :) Only problem is with the getting difference, but before that I need to know how I can check it or how I will get assurance that yes my queries work really fast.. :) - Guruprasad J Rao
You might also want to read this article: blog.codinghorror.com/compiled-or-bust - Evk