NativeQueryNotOptimized

This diagnostics object informs you that a Native Query cannot be optimized. It means that it will be run by instantiating all objects of the candidate class. Try to simplify your query expression.
For an example let's look at a predicate using 2 different unrelated clauses.

ArbitraryQuery.cs
01/* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com */ 02 03using Db4objects.Db4o.Query; 04 05namespace Db4objects.Db4odoc.Diagnostics 06{ 07 public class ArbitraryQuery : Predicate 08 { 09 private int[] _points; 10 public ArbitraryQuery(int[] points) 11 { 12 _points=points; 13 } 14 public bool Match(Pilot pilot) 15 { 16 foreach (int points in _points) 17 { 18 if (pilot.Points == points) 19 { 20 return true; 21 } 22 } 23 return pilot.Name.StartsWith("Rubens"); 24 } 25 } 26}

ArbitraryQuery.vb
01' Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com 02Imports Db4objects.Db4o.Query 03 04Namespace Db4objects.Db4odoc.Diagnostics 05 Public Class ArbitraryQuery 06 Inherits Predicate 07 Private _points() As Integer 08 09 Public Sub New(ByVal points() As Integer) 10 _points = points 11 End Sub 12 13 Public Function Match(ByVal pilot As Evaluations.Pilot) As Boolean 14 Dim points As Integer 15 For Each points In _points 16 If pilot.Points = points Then 17 Return True 18 End If 19 Next 20 Return pilot.Name.StartsWith("Rubens") 21 End Function 22 End Class 23End Namespace

DiagnosticExample.cs: QueryPilot
1private static void QueryPilot(IObjectContainer db){ 2 int[] i = new int[]{19,100}; 3 IObjectSet result = db.Query(new ArbitraryQuery(i)); 4 ListResult(result); 5 }

DiagnosticExample.vb: QueryPilot
1Private Shared Sub QueryPilot(ByVal db As IObjectContainer) 2 Dim i() As Integer = New Integer() {19, 100} 3 4 Dim result As IObjectSet = db.Query(New ArbitraryQuery(i)) 5 ListResult(result) 6 End Sub

DiagnosticExample.cs: TestArbitrary
01public static void TestArbitrary() { 02 Db4oFactory.Configure().Diagnostic().AddListener(new DiagnosticToConsole()); 03 File.Delete(YapFileName); 04 IObjectContainer db=Db4oFactory.OpenFile(YapFileName); 05 try { 06 Pilot pilot = new Pilot("Rubens Barrichello",99); 07 db.Set(pilot); 08 QueryPilot(db); 09 } 10 finally { 11 db.Close(); 12 } 13 }

DiagnosticExample.vb: TestArbitrary
01Public Shared Sub TestArbitrary() 02 Db4oFactory.Configure().Diagnostic().AddListener(New DiagnosticToConsole()) 03 File.Delete(YapFileName) 04 Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 05 Try 06 Dim pilot As Pilot = New Pilot("Rubens Barrichello", 99) 07 db.Set(pilot) 08 QueryPilot(db) 09 Finally 10 db.Close() 11 End Try 12 End Sub