Sunday, October 24, 2010

"Hibernate" for Mono and .NET

Similar to the technologies Hibernate, NHibernate, and LINQ, the Mono platform allows similar technology for working with databases in a object-oriented manner.

The name of the technology is DB4O, and information on it may be found here:

http://www.mono-project.com/DB4O

The organization that maintains DB4O is:

http://www.db4o.com/?src=Mono

At the first link, there is a C# example of working with databases and DB4O, as follows:


using System;

using Db4objects.Db4o;

public class Test {

static string _file = "store.db4o";

// A very basic db4o example that demonstrates
// automatic schema generation and Query-By-Example
public static void Main (string [] args)
{
using (IObjectContainer db = Db4oFactory.OpenFile (_file)) {
db.Set (new Pilot ("Michael Schumacher", 101));
db.Set (new Pilot ("Rubens Barrichello", 99));
db.Commit ();

IObjectSet pilots = db.Get (new Pilot(null, 101));
foreach (Pilot p in pilots) {
Console.WriteLine (p);
}
}
}
}

public class Pilot {

string _name;
int _points;

public Pilot (string name, int points)
{
_name = name;
_points = points;
}

public override string ToString ()
{
return _name + "/" + _points;
}
}




Another option, based on LINQ, can be found at: http://siaqodb.com/

Siaqodb appears to be very interesting too, another option for avoiding direct SQL management.

Enjoy it!

No comments:

Post a Comment