Skip to content

Instantly share code, notes, and snippets.

@gamlerhart
Created March 18, 2010 23:34
Show Gist options
  • Save gamlerhart/337057 to your computer and use it in GitHub Desktop.
Save gamlerhart/337057 to your computer and use it in GitHub Desktop.
public class Program
{
private static void Main(string[] args)
{
File.Delete("tmp.db4o");
using (var db = OpenDB())
{
var usr = new User();
db.Store(usr);
}
using (var db = OpenDB())
{
var usr = GetUser(db);
// we add another item
usr.Tattoos.Add(new Tattoo());
}
using (var db = OpenDB())
{
var usr = GetUser(db);
// returns 1 as expected
Console.Out.WriteLine("Count of tattoos is {0}", usr.Tattoos.Count);
}
Console.Out.WriteLine("DONE, hit enter to exit");
Console.Read();
}
private static User GetUser(IObjectContainer db)
{
return (from User user in db
select user).First();
}
private static IEmbeddedObjectContainer OpenDB()
{
return Db4oEmbedded.OpenFile(NewConfig(), "tmp.db4o");
}
private static IEmbeddedConfiguration NewConfig()
{
var cfg = Db4oEmbedded.NewConfiguration();
cfg.Common.Add(new TransparentPersistenceSupport());
return cfg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment