Making of the db4o LINQPad Driver: LINQPad Drivers
In this little post series I’m going to show how my db4o LINQPad driver is implemented. Some parts of these posts useful for other drivers, other parts will be db4o specific.
Side note: There’s already a new version of the LINQPad driver out which fixes some issues.
The LINQPad website explains well how LINQPad works. For each query LINQPad starts an app domain. This ensures that LINQPad can cleanly kill a query or any code running. For each query LINQPad generates the CIL code dynamically and then runs it.
As I explained in a earlier post you can provide additional assemblies to the query execution context. These assemblies are also included in these app domains. That allows you run use any library in LINQPad.
LINQPad supports different drivers for different data source. A driver is responsible for creating connections, showing the available entities or tables and executing queries. You can find the official documentation here. Also two example drivers are available there.
There are two kinds of drivers, static and dynamic drivers. In static drivers you statically provide a query-context. This means you have to provide an assembly with the code for the entities etc. In a dynamic driver the driver generates the data-context dynamically, including the classes to represent entities.
Packaging a Driver
LINQPad drivers have to be packaged in a certain way to work. Basically a driver is a zip-file with all required assemblies and a description-file. The description-file is called header.xml and contains the name of the driver assembly. The driver-assembly has to be strongly named, otherwise LINQPad won’t accept it. Finally the file-extension for the driver zip file is lpx.
The entry point into the driver is a class which inherits either from the DynamicDataContextDriver or the StaticDataContextDriver class. In that class you need to implement a few things. Like the dialog for creating a new connection, name-properties etc. In the case of a dynamic driver you also have to implement a method to generate to required assemblies at runtime. After that you can ship your driver.
LINQPad supports plugins for all kinds of datasources. You are free to implement your own driver. This site contains the official documentation and example projects.
- db4o Driver for LINQPad
- Fun with NDepend, Part III: Link Collection