Db4o on .NET and Mono
After failing to get a cross-platform sample of NHibernate/Sqlite going, I decided to try out Db4o. This is for a simple, local object persistence layer anyhow, nothing more than a local cache, so db4o sounded perfect.The initial DLLs for 7.4 worked beautifully on .NET but ran into problems on Mono. Apparently db4o imports FlushFileBuffers from kernel32.dll if your build target is not CF or mono. And in its call to FlushFileBuffers it uses FileStream.SafeFileHandle.DangerousGetHandle() which it not yet implemented under Mono, resulting in this exception:
Unhandled Exception: System.NotImplementedException: The requested feature is no t implemented. at System.IO.FileStream.get_SafeFileHandle () [0x00000] at Sharpen.IO.RandomAccessFile.Sync () [0x00000] at Db4objects.Db4o.IO.RandomAccessFileAdapter.Sync () [0x00000] ...
FileStream.Handle. However, that for me just resulted in this:
Unhandled Exception: System.EntryPointNotFoundException: FlushFileBuffers at (wrapper managed-to-native) Sharpen.IO.RandomAccessFile:FlushFileBuffers (intptr) at Sharpen.IO.RandomAccessFile.Sync () [0x00000] at Db4objects.Db4o.IO.RandomAccessFileAdapter.Sync () [0x00000] ...
Being a Linq nut, I immediately decided to skip the Native Query syntax and dive into using the Linq syntax instead. Which worked great on mono 2.0.1, but unfortunately on the current Redhat rpm (stuck back in 1.9.1 lang), the Linq implementation isnt' quite complete and you get this:
Unhandled Exception: System.NotImplementedException: The requested feature is not implemented. at System.Linq.Expressions.MethodCallExpression.Emit (System.Linq.Expressions.EmitContext ec) [0x00000] at System.Linq.Expressions.LambdaExpression.Emit (System.Linq.Expressions.EmitContext ec) [0x00000] at System.Linq.Expressions.LambdaExpression.Compile () [0x00000] at Db4objects.Db4o.Linq.Expressions.SubtreeEvaluator.EvaluateCandidate (System.Linq.Expressions.Expression expression) [0x00000] ...
var items = from RosterItem r in db where r.CreatedAt > DateTime.Now.Subtract(TimeSpan.FromMinutes(10)) select r;
var items = db.Query<RosterItem>(r => r.CreatedAt > DateTime.Now.Subtract(TimeSpan.FromMinutes(10)));
I need to run db4o through some more serious paces, but I like what I see so far.

1 Comments:
Nice! I can post your working binary on the Mono project page if you want. That might help other community members who want to be up and running quickly with db4o v7.4 in Mono.
Best!
German
Post a Comment
<< Home