Created
March 18, 2010 23:34
-
-
Save gamlerhart/337057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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