Skip to content

Instantly share code, notes, and snippets.

@e-tobi
Created April 2, 2013 09:06
Show Gist options
  • Save e-tobi/5290942 to your computer and use it in GitHub Desktop.
Save e-tobi/5290942 to your computer and use it in GitHub Desktop.
RavenDB "caching" not existing documents
using System.Linq;
using Raven.Client.Embedded;
using Raven.Database.Extensions;
namespace etobi.RavenDB2Test01
{
public class Program
{
private static EmbeddableDocumentStore _documentStore;
static void Main(string[] args)
{
IOExtensions.DeleteDirectory("Data");
using (_documentStore = new EmbeddableDocumentStore
{
Configuration =
{
DataDirectory = "Data",
},
})
{
_documentStore.Initialize();
using (var session1 = _documentStore.OpenSession())
{
var foo = session1.Load<Foo>("foos/1");
using (var session2 = _documentStore.OpenSession())
{
session2.Store(new Foo { Id = "foos/1", Name = "Something"});
session2.SaveChanges();
}
foo = session1.Load<Foo>("foos/1");
// foo is still null here
foo = session1.Query<Foo>().FirstOrDefault();
// This actually returns foo
}
}
}
}
public class Foo
{
public string Id { get; set; }
public string Name { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment