Search code examples
c#.netdb4onativequery

which specific conditions could cause a db4o's native query transformation bug?


This fails:

var results = container.Query<SomeClass>(s =>
    s.Field == value && s.AnEnumField != SomeEnum.AnEnumValue
);
Assert.AreEqual(1, results.Count);

But this doesn't:

Predicate<SomeClass> matches = s => 
    s.Field == value && s.AnEnumField != SomeEnum.AnEnumValue;
var results = container.Query<SomeClass>(s => matches(s));
Assert.AreEqual(1, results.Count);

The different in the tests clearly demonstrates the issue happens only when db4o does the expression transformation, as calling a method prevents that. The value checked in the test, is the exact value (no case differences), as the test inserts it first.

Any special conditions where the db4o transformations has bugs with those queries? maybe with .net enums?


I have narrowed it down, and my example above didn't include the troublesome bit. Doesn't have to do with the enum field, but with "value" in the above expression.

Specifically the issue happens when the query includes someInstance.Field for the value, like:

var results =
container.Query<SomeClass>(s =>
   s.Field == someInstance.Field && s.AnEnumField != SomeEnum.AnEnumValue
); 
Assert.AreEqual(1, results.Count);

Solution

  • I finally got to reproduce it in an isolated project (after narrowing it down more in the main project).

    Conditions under which this particular bug occur are very specific. Given the last sample code I posted in the question:

    • SomeClass is a subclass of another class. Field is defined in the base class
    • someInstance in the sample code, must be a subclass of the same base class