views:

224

answers:

1

Hi,

I'm trying db4o and i'm having bad performance when using linq to db4o. (using 7.12)

Here is my configuration :

        var configuration = Db4oFactory.Configure();
        configuration.ObjectClass(typeof(MyTest)).ObjectField("MyInt").Indexed(true);

Here is the object i'm trying to save :

public class MyTest
{
    public int MyInt;
}

And here is my code using linq to db4o (response time 650ms) :

var test = (from c in repo.ObjectContainer.Query<MyTest>()
                        where c.MyInt == 6500
                        select c).FirstOrDefault();

And the same request using native API (response time 28ms) :

var query = repo.ObjectContainer.Query();
query.Descend("MyTest");
query.Descend("MyInt").Constrain(6500)

Can someone tell me what's wrong with linq to db4o ?

Thanks

+6  A: 

Hi

I assume that the repo.ObjectContainer-property is the IObjectContainer-instance, right?

The reason why the index isn't used, is that you're actually using LINQ to Objects and not the db4o-LINQ-Provider.

The method IObjectContainer.Query() retrieves all MyTest instances from the database. And then you run a LINQ to Object query on all this instances. So that why the index isn't used.

To fix this, use the db4o-LINQ-Provider. Ensure that you've added the Db4objects.Db4o.Linq.dll-assembly to your project. An then query the IObjectContainer-instance directly. Like this:

    var test = (from MyTest c in repo.ObjectContainer
                    where c.MyInt == 6500
                    select c).FirstOrDefault();
Gamlor
thanks a lot. I also added this line in the config :configuration.OptimizeNativeQueries(true);And know my query run in 3ms :)
Yann