当前位置: 动力学知识库 > 问答 > 编程问答 >

performance - linq to Db4o not using index

问题描述:

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

网友答案:

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();
分享给朋友:
您可能感兴趣的文章:
随机阅读: