Back to basics: POCO and One to Many relationships (and db4o)

Here is another back to basics post. Howto ‘do’ one-to-many when you are not having a RDBM and using POCO?

Here is the (very simple) model:

For persistance I use Db4o in this example. Please see this blogpost.

One blogentry has many comments. So, we’ll put comments in a List as a attribute of blogentry:

public class BlogEntry
public string blogtitle { get; set; }
public string blogstory { get; set; }
public DateTime postdate { get; set; }
public List<Comment> comments { get; set; }

public BlogEntry()
this.postdate = DateTime.Now;


Here is the comment class:

public class Comment
public string commenttext { get; set; }
public string email { get; set; }
public BlogEntry blogentry { get; set; }


Now we are ready to build our console based blog application:

static void Main(string[] args)
using (var s = SessionFactory.Current)

var b = new BlogEntry { blogtitle = "Lady Gaga FTW",
blogstory = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"

var c = new Comment { blogentry = b, commenttext = "inderdaad", email = "" };
var d = new Comment { blogentry = b, commenttext = "niet mee eens", email = "" };

List<Comment> commentlist = new List<Comment>();
b.comments = commentlist;


//RETRIEVE (2 foreach loops)
var blog = s.All<BlogEntry>();
foreach (BlogEntry ble in blog) {
foreach (Comment cmt in ble.comments)
Console.WriteLine("Comment: ");

So, when I execute this application a few times, the db40 file gets a bit stuffed and I get the following output, which is a full blown console blog application:

Oh well, I said it was a back to basics post, didn’t I. 🙂

Tooltip for this month SSMA for MySQL

Since Sun MicroSystems has been aquired by Oracle, Some people have had their doubts about the future of MySQL, ofcourse there is MariaDB, a fairly new MySQL solution founded by the masterbrain behind MySQL, Monthy. But it just doesn’t do it ‘yet’ for the bigger audience, i never heard a client ask for a MariaDB database solution, the questions are always the same, Are we going to use Oracle or Microsoft and what are the organization costs to implement and support?

SQL 2008 Express

If you are a personal or a non heavy user of databases Microsoft released the MSSQL Express edition, a free SQL database version that supports databases up to 10 GB. Read more about the free Microsoft SQL 2008 R2 Express here. And to make it even easier for you, Microsoft has now released the MySQL migration Assistent (SSMA) at the 12th of August. The SSMA tool is available for servers SQL2005, 2008, 2008 R2 and SQL Azure and is compatible with MySQL version 4.2 and higher, also suitable for 64 bit platforms. So what’s keeping you up? For everyone who still has doubts, Microsoft will now convince you. After a SQL migration assistant for Oracle, Access and SyBase, MySQl has been added to this list. A pretty smart move for Microsoft to generate even more new clients, who still had cold feet, thinking about costs and downtime of the servers, there is no longer an excuse. Microsoft is listening, improving and on the move!