1. First Glance

Before diving straight into the first source code samples let's get you familiar with some basics.


    1.1. The db4o engine

    The db4o object database engine consists of one single DLL. This is all that you need to program against. The versions supplied with the distribution can be found in /db4o-7.4/bin/.

    db4o is available in multiple distributions for Microsoft .NET. One downloadable distribution is for the .NET Framework 1.0/1.1 and the other is for the .NET Framework 2.0. Be sure to download and use the correct one for your project environment.

    /db4o-7.4/bin/net-2.0/Db4objects.Db4o.dll
    is the standard db4o engine for the .NET 2.0 framework.

    /db4o-7.4/bin/compact-2.0/Db4objects.Db4o.dll
    is built for the .NET 2.0 CompactFramework.

    /db4o-7.4/bin/net-3.5/Db4objects.Db4o.dll
    is the standard db4o engine for the .NET 3.5 framework.

    /db4o-7.4/bin/compact-3.5/Db4objects.Db4o.dll
    is built for the .NET 3.5 CompactFramework.


    1.2. Installation

    To use db4o in a development project, you only need to add one of the above Db4objects.Db4o.dll files to your project references.


    1.3. API Overview

    Do not forget the API documentation while reading through this tutorial. It provides an organized view of the API, looking from a namespace perspective and you may find related functionality to the theme you are currently reading up on.

    For starters, the Db4objects.Db4o and Db4objects.Db4o.Query namespaces are all that you need to worry about.

    Db4objects.Db4o

    The Db4objects.Db4o namespace contains most of the functionality you will commonly need when you work with db4o. Two classes of special interest are Db4objects.Db4o.Db4oFactory and Db4objects.Db4o.IObjectContainer.

    The Db4oFactory is your starting point. Static methods in this class allow you to open a database file, start a server, or connect to an existing server. It also lets you configure the db4o environment before opening a database.

    The most important interface, and the one that you will be using 99% of the time is
    IObjectContainer: This is your db4o database.
    - An IObjectContainer can either be a database in single-user mode or a client connection to a db4o server.
    - Every IObjectContainer owns one transaction. All work is transactional. When you open an IObjectContainer, you are in a transaction, when you Commit() or Rollback(), the next transaction is started immediately.
    - Every IObjectContainer maintains it's own references to stored and instantiated objects. In doing so, it manages object identities, and is able to achieve a high level of performance.
    - IObjectContainers are intended to be kept open as long as you work against them. When you close an IObjectContainer, all database references to objects in RAM will be discarded.

    Db4objects.Db4o.Ext

    In case you wonder why you only see very few methods in an IObjectContainer, here is why: The db4o interface is supplied in two steps in two namespaces, Db4objects.Db4o and Db4objects.Db4o.Ext for the following reasons:
    - It's easier to get started, because the important methods are emphasized.
    - It will be easier for other products to copy the basic db4o interface.
    - It is an example of how a lightweight version of db4o could look.

    Every IObjectContainer object is also an IExtObjectContainer. You can cast the IObjectContainer to IExtObjectContainer or you can use the .Ext() method to access advanced features.

    Db4objects.Db4o.Config

    The Db4objects.Db4o.Config namespace contains types necessary to configure db4o. The objects and interfaces within are discussed in the Configuration section.

     Db4objects.Db4o.Query

    The Db4objects.Db4o.Query namespace contains the Predicate class to construct Native Queries. The Native Query interface is the primary db4o querying interface and should be preferred over the Soda Query API .




    www.db4o.com