Query Batch: Concrete Syntax
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
Great post!
Comment preview