Search code examples
c#.netdb4osoda

how to check for an empty collection in a db4o's SODA query


As the title says, is there a way to check for an empty collection in a SODA query?

I can check if the collection field is set to null and check property values in the collection elements, but don't know how to check if the collection has no elements.

Any help is appreciated :)


Edit 1: I do know how to make the query happen outside the db4o filtering i.e. by switching to use Native Queries or LINQ; or doing the equivalent that happens when checking the collection's count, which is using an Evaluation.

I'm actually trying to avoid the activations caused by a Native Query that was in there, as it really hits us in performance in our scenario.


Solution

  • I had no luck searching for a solution or trying any options with Count or Size as the checks. After trying different options with a few focused integration tests to back it up, I found one that does the trick:

    Given a field _list of type List:

    ...
    query.Descend("_list").Constrain(typeof(Item)).Not();
    ...
    

    It effectively returns only the records that have no items in the list, as those are the only ones that pass the check of not having items of type Item. It works for both cases, when _list is in null or is an empty list.