Hi,
Until recently .Net enums had no special handling in db4o, i.e, they were seem as any other object and were handled as such. The issue with this approach is that enums are not reference types; enums are value types and so object behavior don't hold for them (for instance, there's no such thing as an enum identity).
In the practice this caused some strange behaviors when storing / querying enums fields:
- COR-1476: 0 (zero) was handled as a special value meaning "match any value".
- COR-1028: Enums where handled as references instead of value types.
You can see issue #1 manifestation by constraining a query using an enum field with value 0; instead of getting back only objects matching the enum field value (zero) you'll get all objects (no matter the value of the enum). Since, by default, .Net enums starts with 0 (zero) this was really annoying. A possible workaround (which is,IMHO, suboptimal) requires that you change your enums definitions to start with 1 (instead of zero).
In the second issue, a new "instance" of an enum were added to the database every time an object containing enum fields got updated.
We are proud to let you know that these behaviors/annoyances were fixed in version 7.8 (scheduled to be released soon as development release).
Instead of just talking about these issues I'd rather like to show you a sample so you can see it by yourself. The accompanying application populates a database with some objects containing enums and then queries for objects (constraining to a specific enum value) to demonstrate issue #1; also it asks Db4o how many "instances" it holds for a specific enum value to demonstrate issue #2.
Start the application and follow the steps:
- Select which versions you want to run the test against (by default only versions 7.4 and 7.8 are available but you can download other versions and experiment with them also);
- Select the enum value to constrain the query to (by default foo which is assigned 0);
- Press "Run" button.

The application will show you how many enum "instances" are stored in the database (issue #2) and the results of the query (issue #1). Note that starting with version 7.8 Db4o will report 0 (zero) as the enum "instance" count (since they are not stored as reference types anymore) and the query will bring the right results.
Notice that "unoptimized native queries" will render the right result since it runs as an evaluation.
To play with the source code for this post get it from our svn:
svn co https://source.db4o.com/db4o/trunk/sandbox/Adriano/Blogs/EnumHandling/
What do you think?
Best
Adriano