views:

37

answers:

1

Hey there - simple query:

var q = (from SomeObject o in container
    where 
 o.SomeInt > 8 
 && o.SomeString != null //Null Ref here
    select o;

I always get a null reference exception.

If I use String.IsNullOrEmpty(o.SomeString) the query takes about 100 times as long, as if I use && o.SomeString != "" (which is way faster, but obviously not correct).

I'm guessing because DB4o needs to activate the objects, in order to pass them in to the IsNullOrEmpty call, and can't use the indexes.

My question is, what's a better way to check for nulls in this situation? Is there something like: mystring != Db4o.DBNull.Value, or something?

Cheers, Dave

+3  A: 

Hi Dave

Actually your query should work without any issues. You're query should just run fine. It also shouldn't require any activation. db4o tries to translate the queries into SODA-Queries and avoid activating the objects.

Which version of db4o are you using? There was a bug which caused a NullRefrence-Exception in LINQ-Queries. It should be fixed.

Have you added the Db4objects.Db4o.Linq.dll assembly to your project. Are the mono-assemblies present?

I would tried to avoid using String.IsNullOrEmpty at the moment, because I will prevent the query-optimization. As soon a you call complex methods withing your query, the optimizer won't be able to translate the query into SODA. Then you run basically LINQ to Objects, which will be slow on a large dataset.

Gamlor
Hey - thanks for your reply, you're quite helpful with this Db4o stuff. It's appreciated.I just upgraded all the DLL's to be the most recent release, now the query runs - however none of my indexes work any more. *sigh*I've enabled logging to the console, and I'm not getting any messages about missing indexes (as you helped me with, on an earlier post of mine).Any ideas? :(Cheers,Dave
Dave
Hmm that's strange. Do you see any new 'Db4objects.Db4o.Linq.QueryOptimizationException' in the Output-Window in Visual-Studio? That would indicate that query isn't optimized anymore. Check that you've there's 'Mono.Reflection.dll' along the 'Db4objects.Db4o.Linq.dll'-assembly if your switched to the 8.0 beta-version. That's a new dependency instead of the Cecil-assemblies.Anyway, it's strange and should be investigated.
Gamlor
I was using the latest v7 Dll's. I've upgraded to the beta, and everything seems ok now. Thanks again for your help.Dave
Dave