Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 18 | Comments: 72

filter by tags archive

Query Batch: Concrete Syntax

time to read 3 min | 417 words

Thanks for all the feedback about this feature, I have implemented it and you can find the code here.  Instead of explaining, I am going to let the test speak for themselves. Consider this a first iteration, and I am now accepting patches for this. :-)

 

[Test]
public void CanUseCriteriaBatch()
{
    ICollection<SMS> loadedMSGs = null;
    new CriteriaBatch(session)
        .Add(DetachedCriteria.For<SMS>(), Order.Asc("id"))
        .OnRead<SMS>(delegate(ICollection<SMS> msgs) { loadedMSGs = msgs; })
        .Execute();
    Assert.IsNotNull(loadedMSGs);
}

[Test]
public void CanUseCriteriaBatchForUniqueResult()
{
    ICollection<SMS> loadedMSGs = null;
    SMS loadedMsg = null;
    new CriteriaBatch(session)
        .Add(DetachedCriteria.For<SMS>(), Order.Asc("id"))
            .OnRead<SMS>(delegate(ICollection<SMS> msgs) { loadedMSGs = msgs; })
        .Add(DetachedCriteria.For<SMS>())
            .Paging(0, 1)
            .OnRead<SMS>(delegate(SMS msg) { loadedMsg = msg; })
        .Execute();
    Assert.IsNotNull(loadedMSGs);
    Assert.IsNotNull(loadedMsg);
}

[Test]
public void CanUseCriteriaBatchWithAutomaticCountQuery()
{
    ICollection<SMS> loadedMSGs = null;
    int msg_count = 0;
    SMS loadedMsg = null;
    new CriteriaBatch(session)
     .Add(DetachedCriteria.For<SMS>(), Order.Asc("id"))
         .OnRead<SMS>(delegate(ICollection<SMS> msgs, int count) { loadedMSGs = msgs;
                                                                     msg_count = count;})
     .Add(DetachedCriteria.For<SMS>())
         .Paging(0, 1)
          .OnRead<SMS>(delegate(SMS msg) { loadedMsg = msg; })
    .Execute();
    Assert.IsNotNull(loadedMSGs);
    Assert.AreEqual(1, msg_count);
    Assert.IsNotNull(loadedMsg);

}

Comments

Maor

Great post!

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. RavenDB 3.0 New Stable Release - 17 hours from now
  2. Production postmortem: The industry at large - about one day from now
  3. The insidious cost of allocations - 3 days from now
  4. Buffer allocation strategies: A possible solution - 6 days from now
  5. Buffer allocation strategies: Explaining the solution - 7 days from now

And 3 more posts are pending...

There are posts all the way to Sep 11, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    01 Sep 2015 - The case of the lying configuration file
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

RECENT COMMENTS

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats