Skip to content

Instantly share code, notes, and snippets.

@amarraja
Created April 29, 2013 10:32
Show Gist options
  • Save amarraja/5480858 to your computer and use it in GitHub Desktop.
Save amarraja/5480858 to your computer and use it in GitHub Desktop.
public class StoreTest
{
public class Holder
{
public string SomeString { get; set; }
}
public class HolderIndex : AbstractIndexCreationTask<Holder, HolderIndex.ReduceResult>
{
public class ReduceResult
{
public string SomeString { get; set; }
}
public HolderIndex()
{
Map = holders => from holder in holders
select new {holder.SomeString};
}
}
[Test]
public void NoStoreGetsFieldFromIndex()
{
var dataDir = "c:\\raventests\\" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
if (!Directory.Exists(dataDir))
Directory.CreateDirectory(dataDir);
var store = new EmbeddableDocumentStore() { DataDirectory = dataDir }.Initialize();
using (store)
{
new HolderIndex().Execute(store);
using (var s = store.OpenSession())
{
s.Store(new Holder() { SomeString = "CamelCased"});
s.SaveChanges();
}
using (var s = store.OpenSession())
{
var holder = s.Query<HolderIndex.ReduceResult, HolderIndex>()
.Customize(c => c.WaitForNonStaleResults())
.AsProjection<HolderIndex.ReduceResult>()
.Where(n => n.SomeString == "camelcased")
.First();
//This prints "CamelCased", when I would expect it to be "camelcased"
//as I have not indicated the field is stored
Trace.WriteLine(holder.SomeString);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment