db4o Driver for LINQPad

LINQPad and db4o

LINQPad and db4o

Way back in my posts about db4o I complained about the missing tool support. I also demonstrated how to use LINQPad for ad hoc queries. However wouldn’t it be cooler if you can access db4o databases more directly with LINQPad? Like a relational databases? Well that’s possible by creating a driver for LINQPad. That’s what I’ve developed, a small prototype driver for db4o!

 

 

The driver allows you to open db4o databases like any other database in LINQPad. You can query it without providing the original classes. Just open it and start writing LINQ queries against it.

How to Use It

The plugin only works with .NET 4.0 and the LINQPad version for 4.0. Download the plugin-file and save it somewhere. Open LINQPad and add a new connection. Click on ‘View more drivers’ and there on ‘Browse’. Now choose the downloaded lpx-file and confirm it. Afterwards choose the ‘db4o Driver’ on the list and proceed. Now a dialog shows up which lets you choose a database file. Choose the database file which you want to open.

After that there is an entry of it on the left, with a list of stored classes and fields. In the query-window you can start to write queries. Use the class-names as the data-source. For example to query instances of the Car class just write queries like this ‘from c in Car select c’.

Using the Driver

Using the Driver

Limitations and Bugs

Of course the implementation is in a very early stage. It probably crashes with complex data models. Let me know of cases which don’t work. Anyhow here’s a list of issues and limitations.

  • Name collisions can happen and cause issues/crashes: With generics, same class-names in different namespaces, field-names etc.
  • Right now you cannot use your original assemblies to access the database. And if you load your own assemblies into LINQPad it probably crashes.
  • At the moment all fields are accessible by the field-name and a property name. When you’re class has a field called ‘name’ you can access it also with the name ‘Name’. That is a bit confusing.
  • Complex types may cause crashes, especially with array-fields.
  • No support for client-server mode and configuring your database.
  • Advanced db4o features like your own type-handler will cause a crash.
  • It uses its own db4o version (8.1.184.15492). You cannot provide the db4o version you want to use.
  • It is slow.

Planned Features

So here’s an overview of the features I’m planning to implement:

  • Option to load assemblies with the original classes.
  • More stability against name collisions. Although I’m not aiming for solving 100% of all cases.
  • Insert and update support.
  • Access to some meta-data. For example if a field is indexed or not.

And let me also tell the features I’m not going to implement. (Of course you can implement that yourself and contribute it.)

  • Client-Server mode: I’m not really interested in that.
  • .NET 3.5 or Mono support. I’m focusing only on 4.0.

How is it Implemented?

Well I’m going to elaborate the implementation-details in future posts. Roughly it works like this: First open the db4o database and read the meta-data. Then resolve well-known types. For each unknown type generate dynamically a type. Finally generate a database-context for LINQPad which contains the entry-points for all queries.

Currently the source is available on my scratch repository on Github. Probably I’ll create a proper project and also mirror it on GitHub.

Final Word

Try it yourself ;). Here’s the download.

Tagged on: , ,

3 thoughts on “db4o Driver for LINQPad

  1. Jay

    Was waiting for some thing like but when I tried to open a file I got the following error

    Error: Cannot cccess value if no value is set

  2. gamlerhart Post author

    As said it’s still more or less a prototype. Can you send me a database which produces that error? Then can I check what’s not working.

  3. ale

    Does the file needs to be with the .db4o extension?

    As my file is a .db and I am thrown an “InvalidCastException” in LINQPAD 5.

Leave a Reply

Your email address will not be published. Required fields are marked *