Sunday, June 28, 2009

db4o - an Object-Database


Versant have come up with an object-database that is very easy to use.


In some cases, performance might not be there when you need it, but when this isn't a problem the benefits easily stack up.


const string dbFile = @"C:\FearlessOnes\db\Monsters.db";

IMonster monster = new Horror("Atlach-Nacha",
"Spinner in Darkness");

// If the database doesn't exist, it will be created
using (IObjectContainer db = Db4oFactory.OpenFile(dbFile))
{
db.Store(monster);
}

Nice and easy. Linq is also supported,


using (IObjectContainer db = Db4oFactory.OpenFile(dbFile))
{
monster = (from IMonster m in db.Query(typeof(IMonster))
where m.Name == "Atlach-Nacha"
select m).Single();

monster.Mode = MonsterMode.Hungry;
db.Store(monster);
}

Just reference one DLL, or two if you want to use Linq, and you're smiling.


A great tool for developing the domain layer, even if you plan to use a relational database later. Download it here. The documentation is also very good.


4 comments:

  1. I hope the DB4o folks improve their LINQ support. Right now, doing a projection in a LINQ query basically means your LINQ query will run entirely in-memory, activating tons of objects in the process:

    // Oh nooes! This activates all 5000 monsters in the database, even though we only want their names.
    var monsterNames = from IMonster m in db select m.Name;

    ReplyDelete
  2. Yes, it seems to pack a few hidden gems unfortunatelly. Thanks for the heads-up.

    I've just started using it for my game stuff, and so far so good. I hope it can stand its ground out in the wild though because I'd like to use it for a small website at work. I'm a bit nervous it can't handle the jandle though.

    ReplyDelete
  3. Speaking of open source, object-oriented embedded databases, you should also check out McObject’s Perst. Versions are available for .NET (including .NET Compact Framework and Silverlight), Java (including Android) and Java ME (for those BlackBerry midlets). More info on the Perst object-oriented embedded database - http://www.mcobject.com/perst

    ReplyDelete
  4. Try EffiPRoz Database (www.EffiProz.com).
    EffiProz is a database written entirely in C#. EffiProz has full-blown SQL support, including SQL Stored Procedures, Functions, and Triggers. Ideal for embedding in .Net applications. Support Silverlight 3 and .Net compact framework as well.
    Comes with Visual Studio ad-in, ADO.Net provider, Entity Framework

    ReplyDelete