You can use a class base to query for inherited objects. This makes a query path a bit more complex and may result in a small performance degrade.
QueryPerformanceBenchmark.cs: RunInheritanceTest
private void RunInheritanceTest()
{
Init();
Clean();
System.Console.WriteLine("Storing " + _count +
" objects of depth " + _depth);
Open(Configure());
Store();
Close();
Open(Configure());
StartTimer();
IQuery query = objectContainer.Query();
query.Constrain(typeof(Item));
query.Descend("_name").Constrain("level1/1");
Item item = (Item)query.Execute().Next();
StopTimer("Select 1 object: " + item._name);
Close();
Clean();
System.Console.WriteLine("Storing " + _count +
" inherited objects of depth "
+ _depth);
Open(Configure());
StoreInherited();
Close();
Open(Configure());
StartTimer();
// Query for item, inheriting objects
// should be included in the result
query = objectContainer.Query();
query.Constrain(typeof(Item));
query.Descend("_name").Constrain("level1/1");
item = (Item)query.Execute().Next();
StopTimer("Select 1 object: " + item._name);
Close();
}
QueryPerformanceBenchmark.cs: ItemDerived
public class ItemDerived : Item
{
public ItemDerived(string name, ItemDerived child)
: base(name, child)
{
}
}
QueryPerformanceBenchmark.cs: Init
private void Init()
{
_filePath = "performance.db4o";
// amount of objects
_count = 10000;
// depth of objects
_depth = 3;
_isClientServer = false;
}
QueryPerformanceBenchmark.cs: Configure
private IConfiguration Configure()
{
IConfiguration config = Db4oFactory.NewConfiguration();
return config;
}
Results from the test machine:
Storing 10000 objects of depth 3
Store 30000 objects: 2236ms
Select 1 object: level1/1: 457ms
Storing 10000 inherited objects of depth 3
Store 30000 objects: 2790ms
Select 1 object: level1/1: 595ms
Download example code: