2

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?

Community
  • 1
  • 1
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200
  • 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 May 31 '16 at 12:09
  • 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 May 31 '16 at 12:12
  • 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 May 31 '16 at 12:19
  • 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 May 31 '16 at 12:21
  • 1
    You might also want to read this article: https://blog.codinghorror.com/compiled-or-bust/ – Evk May 31 '16 at 12:24
  • Yea I've read that prior to this question.. Following few of stuffs.. :) Thanks for the info again.. :) – Guruprasad J Rao May 31 '16 at 12:27

0 Answers0