Query built using Entity Framework

entity-framework linq

Question

How do I create a compiled query for this Entity Framework LINQ query?

var context = new SlxDbContext();
var userSet = context.Set<User>();
User user = userSet.Where(x => x.UserName == "gstrader").First();
1
4
3/16/2012 4:01:22 PM

Popular Answer

CompiledQuery only functions with ObjectContext; there is no way to utilize it with the DbContext API. You are probably utilizing the DbContext API if you are using Code First. Additionally, Microsoft advises using the DbContext API in all new projects, whether you'll be using Database First or Model First models.

However, using EF5 pulls up compiled automatically, which operate significantly differently from CompiledQuery. EF5 stores the created SQL for you as a background process, then examines the cache for previously compiled queries when you run any query. This eliminates the requirement for you to write code to compile each query and then invoke each as required.

See:

http://blogs.msdn.com/b/adonet/archive/2012/02/14/sneak-preview-entity-framework-5-0-performance-improvements.aspx

and

http://www.devproconnections.com/article/entity-framework/entity-framework-5-143875

5
4/15/2013 8:52:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow