Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many times does a compiled query have to recompile during the lifecycle of an application?

In a website, if I have a class:

public class Provider
{
    static readonly Func<Entities, IEnumerable<Tag>> AllTags =
        CompiledQuery.Compile<Entities, IEnumerable<Tag>>
        (
            e => e.Tags
        );

    public IEnumerable<Tag> GetAll()
    {
        using (var db = new Entities())
        {
            return AllTags(db).ToList();
        }
    }
}

In a page I have:

protected void Page_Load(object sender, EventArgs ev)
{
    (new Provider()).GetAll();
}

How many times the query will be compiled? Every time the page loads...? Once in the application...?

like image 813
BrunoLM Avatar asked Feb 08 '11 12:02

BrunoLM


2 Answers

since it is a static member, once when class is loaded in app domain.

like image 101
Mubashir Khan Avatar answered Oct 20 '22 08:10

Mubashir Khan


Seeing it is compiled. I would say once. Why would it need to be recompiled? Isn't that the point of compiled queries?

Given the compiled query is static, once per application instance/lifetime. Note: Lifetimes may overlap.

like image 38
leppie Avatar answered Oct 20 '22 06:10

leppie