Search code examples
c#asp.netlifecyclecompiled-query

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...?


Solution

  • 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.