2011-05-03 11 views
9

के बाद RavenDB में परिणामों को अपडेट करने का इंतजार कैसे करूं मैं रावेन डीबी के साथ रिपोजिटरी पैटर्न का उपयोग कर रहा हूं। मेरे भंडार इंटरफ़ेसमैं DEVETE

public interface IRepository<T> where T : Entity 
{ 
    IEnumerable<T> Find(Func<T, bool> exp); 
    void Delete(T entity); 
    void Save(); 
    ... 
} 

है और कार्यान्वयन

public class Repository<T> : IRepository<T> where T : Entity 
{ 
    public IEnumerable<T> Find(Func<T, bool> exp) 
    { 
     return session.Query<T>().Where(exp); 
    } 

    public void Delete(T entity) 
    { 
     session.Delete(entity); 
    } 

    public void Save() 
    { 
     session.SaveChanges(); 
    } 
    ... 
} 

मैं एक परीक्षण है कि हटाने के लिए सभी संस्थाओं के निशान, है परिवर्तन और क्वेरी डेटाबेस की बचत होती है, तो परिणाम गिनती शून्य

[Test] 
public void DeleteValueTest() 
{ 
    //resolve repository 
    var repository = ContainerService.Instance.Resolve<IRepository<DummyType>>(); 
    Func<DummyType, bool> dummyTypeExpr = item => item.GetType() == typeof(DummyType); 

    //find all entries of dummy types and mark for deletion 
    var items = repository.Find(dummyTypeExpr); 
    foreach (var item in items) 
    { 
     repository.Delete(item); 
    } 
    //commit changes 
    repository.Save(); 


    //populate all dummy types, shall be nothing in there 
    items = repository.Find(dummyTypeExpr); 
    int actualCount = items.Count(); 
    int expectedCount = 0; 

    Assert.AreEqual(expectedCount, actualCount); 
} 
है देखने के लिए है

परीक्षण नमूना आउटपुट

RepositoryTest.DeleteValueTest : FailedExecuting query '' on index 'dynamic/DummyTypes' in 'http://localhost:8080' 
Query returned 5/5 results 
Saving 1 changes to http://localhost:8080 
Executing query '' on index 'dynamic/DummyTypes' in 'http://localhost:8080' 
Query returned 4/5 results 

Expected: 0 
But was: 4 
के साथ विफल रहता है

समस्या यह है कि यदि मैं इस परीक्षा को कई बार चलाता हूं, तो वास्तव में वस्तुओं को हटाया जा रहा है (एक समय में 2-3 आइटम)। मैंने देखा कि एक IDocumentQuery है जिसमें WaitForNonStaleResults विधि है।

IDocumentQuery<T> WaitForNonStaleResults(); 

लेकिन मैं नहीं मिल सकता है यह में नाम स्थान कि NuGet द्वारा स्थापित किया गया था Raven.Client.Lightweight।

को समेटने के लिए मैं डेटाबेस को अपडेट होने तक कैसे प्रतीक्षा करूं और मैं ताजा डेटा कैसे पढ़ूं। क्या मैं कुछ गलत कर रहा हूँ? आपकी सहायताके लिए धन्यवाद!

+0

ऐसा लगता है कि एक ही इंटरफ़ेस _IDocumentQuery_ ** ही ** नाम स्थान _Raven.Client_ में अलग ढंग से परिभाषित किया गया है। हालांकि, दो अलग-अलग असेंबली हैं जो इस इंटरफ़ेस की आपूर्ति करती हैं: _Raven.Client.dll_ और _Raven.Client.Lightweight.dll_। NuGet मुझे बाद की पुस्तकालय के साथ प्रदान करता है। – oleksii

+0

Raven.Client.dll कई महीनों के लिए उपयोग में नहीं है, आप किस निर्माण का उपयोग कर रहे हैं? –

+0

किसी भी दर पर, रोजा का जवाब सही है –

उत्तर

12
Session.Query<Foo>().Customize(x=>x.WaitForNonStaleResults()) 

कृपया ध्यान दें कि इसका उपयोग करने की अनुशंसा नहीं की जाती है। कम से कम, का उपयोग WaitForNonStaleResultsAsOfNow

में

Ayende की प्रतिक्रिया के अनुसार:

http://groups.google.com/group/ravendb/browse_thread/thread/32c8e7e2453efed6/090b2e0a9c722e9f?#090b2e0a9c722e9f

+0

किसी भी समय! वोट अप करने के लिए स्वतंत्र महसूस करें;) –