开发者

RavenDB Paging Behaviour

开发者 https://www.devze.com 2023-03-29 07:21 出处:网络
I have the following test for skip take - [Test] public void RavenPagingBehaviour() { const int count = 2048;

I have the following test for skip take -

    [Test]
    public void RavenPagingBehaviour()
    {
        const int count = 2048;
        var eventEntities = PopulateEvents(count);
        PopulateEventsToRaven(eventEntities);

        using (var session = Store.OpenSession(_testDataBase))
        {
            var queryable =
                session.Query<EventEntity>().Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()).Skip(0).Take(1024);

            var entities = queryable.ToArray();

            foreach (var eventEntity in entities)
            {
                eventEntity.Key = "Modified";
            }

            session.SaveChanges();

            queryable = session.Query<EventEntity>().Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()).Skip(0).Take(1024);

            entities = queryable.ToArray();

            foreach (var eventEntity in entities)
            {
                Assert.AreEqual(eventEntity.Key, "Modified");
            }
        }
    }

PopulateEventsToRaven simply adds 2048 very simple documents to the database.

The first skip take combination gets the first 1024 doucuments modifies the documents and then commits changes.

The next skip take combination again wants to get the first 1024 documents but this time it gets the document number 1024 to开发者_JAVA百科 2048 and hence fails the test. Why is this , I would expect the first 1024 again?

Edit: I have varified that if I dont modify the documents the behaviour is fine.


The problem is that you don't specify an order by, and that means that RavenDB is free to choose with items to return, those aren't necessarily going to be the same items that it returned in the previous call. Use an OrderBy and it will be consistent.

0

精彩评论

暂无评论...
验证码 换一张
取 消