db4o querying subobject

Go To StackoverFlow.com

0

I've just started with db4o and I stumbled on to a problem.

I have an object with a subobject (it is probably not the correct word but I hope you get what I mean).

The subobject contains two dates, one start date and one end date.

I would like to show the main object if it has at least one sub object where DateTime.Now is inbetween the start and end date.

I have to use native query or SODA (linq isn't working in the project).

Thanks in advance!

/Fredrik

2009-06-16 07:45
by Fred


4

I would try something like this:

IQuery query = db.Query();
query.Constrain(typeof(YourObjectType));
IConstraint constr1 = query.Descend("enddate")
    .Constrain(DateTime.Now).Greater();
IConstraint constr2 = query.Descend("startdate")
    .Constrain(DateTime.Now).Smaller();
query.Constrain(constr1).And(constr2);
IObjectSet result = query.Execute();
2009-09-11 00:40
by mr_georg
Thanks, this fixed my problem as well - Contango 2011-02-23 17:57
Ads