Home

Refresh Schema Explorer programmatically from dynamic driver

I'm creating a dynamic driver. I would like to allow the users of the driver to configure the driver via an API embedded in the driver and when they have, I want to programmatically kick off a schema explorer refresh.

I've read about overriding GetLastSchemaUpdate which will react to "old fashioned" SQL statements, but this doesn't suit my needs.

Is there a way?

Comments

  • There's no way to do this, and it's a reasonable request.

    Would it help if I added the following method to IConnectionInfo?

    Task ForceRefresh();
    

    The obvious place to call this would be in the OnQueryFinishing method of your DataContextDriver. However, you could call it earlier if you cached the IConnectionInfo:

    static IConnectionInfo _currentCxInfo;    
    public override void InitializeContext (IConnectionInfo cxInfo, object context, ...)
    {
        _currentCxInfo = cxInfo;
    }
    

    Would this work for you?

  • I believe that would do the trick. Thanks!

  • edited May 22

    This feature is now supported in the latest beta (6.9.2). Note that for now, you will need to reference the latest preview package of LINQPad.Reference (1.2.0-beta) in your driver project.

    Let me know how you get along.

  • Thanks, joe. I'll test shortly.

  • edited May 22

    This works well for me:

    public override void OnQueryFinishing(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
    {    
    #if NETCORE
        dynamic dontext = context;
        if (dontext.RefreshConnection)
            cxInfo.ForceRefresh();
    #endif
    
        base.OnQueryFinishing(cxInfo, context, executionManager);
    }
    

    I noticed that the reference assembly for LINQPad 5 did not include the new method. Will cxInfo.ForceRefresh() be available in v5?

  • I wanted to handle the absence of ForceRefresh() gracefully, like this:

    void RefreshConnectionIfNeeded(dynamic context, dynamic cxInfo)
    {
        // using dynamic for the context
        // because it's generated at runtime
    
        // using dynamic for the cxInfo instance
        // because ForceRefresh() is new and older
        // version of linqpad won't have the method
    
        if (context.RefreshConnection)
        {
            try
            {
                cxInfo.ForceRefresh();
            }
            catch (RuntimeBinderException)
            {
                "Refresh the connection to apply changes.".Dump();
            }
        }
    }
    

    This won't work because ForceRefresh() is a default interface implementation. Apparently the DLR cannot dispatch to those.

  • Looks like reflection will work for me.

  • edited May 23

    You could do this:

    void RefreshConnection (IConnectionInfo cxInfo)
    {
        if (this.LINQPadVersion >= new Version (6, 9, 2)) ForceRefresh (cxInfo);
    }
    
    static void ForceRefresh (IConnectionInfo cxInfo)
    {
    #if NETCORE
        cxInfo.ForceRefresh ();
    #endif
    }
    
Sign In or Register to comment.