Custom driver - Multiple databases
I'm writing a custom driver, is there a way to have the same functionality as the "Display in a treeview" one from LINQPad where multiple databases are displayed in the tree view and the connections dropdown list? Especially the part where selecting the server-name.database-name from the dropdown changes the context of the query?
Comments
-
This is possible - you'll need to override these properties of DataContextDriver:
/// <summary>Returns whether the connection a parent (default false). Parent connections can't themselves be queried, but they /// have children which are queryable. An example is a SQL Server connection with the 'Show all databases in treeview' /// option enabled: the parent displays the server, and the children are the databases. If you override this to return true, /// also override the GetChildren method.</summary> public virtual bool IsParent (IConnectionInfo cxInfo) => false; /// <summary>For connections for which IsParent returns true, this should be overridden to return the child connections. /// To create a child connection, call CreateChild on cxInfo (this clones all the properties), then assign the Database property /// on the child (or whichever properties you want to specialize).</summary> public virtual IConnectionInfo[] GetChildren (IConnectionInfo cxInfo, bool isOnStartup) => null; /// <summary>Optional - If you're implementing a connection hierarchy ("Show all databases in treeview"), /// override this to return the child node text.</summary> public virtual string GetChildNodeName (IConnectionInfo cxInfo) => cxInfo.DatabaseInfo.Database; /// <summary>Optional - if you're implementing a connection hierarchy ("Show all databases in treeview"), /// you can override this to let users query more than one connection at a time.</summary> public virtual void MergeConnections (ConnectionMergeArgs args) { } -
Thank you for your response. I did find those while spelunking a bit, but it seems the
GetChildrenmethod is not called even ifIsParentreturnstrue.Adding this to the
UniversalStaticDriverclass of the demo project show that onlyIsParentis called.public override bool IsParent(IConnectionInfo cxInfo) { return true; } public override IConnectionInfo[] GetChildren(IConnectionInfo cxInfo, bool isOnStartup) { var child1 = cxInfo.CreateChild(); var child2 = cxInfo.CreateChild (); return new[] { child1, child2, }; } -
Right now, this feature is available only with dynamic drivers.
