开发者

DB4o Linq query - How to check for null strings

Hey there - simple query:

var q = (from SomeObject o in container
    where 
 o.SomeInt > 8 
 &开发者_StackOverflow;& 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜