Created
October 2, 2013 16:26
-
-
Save kijanawoodard/6796416 to your computer and use it in GitHub Desktop.
OrderBy on a dictionary in a Transformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class TransformerDictionaryOrderTests : RavenTestBase | |
{ | |
[Test] | |
public void CanOrderADictionary() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
new FooTransformer().Execute(store); | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(new Foo {Id = "foos/1", Dates = {{"hello", DateTimeOffset.UtcNow}}}); | |
session.SaveChanges(); | |
var results = session.Load<FooTransformer, FooTransformer.Result>("foos/1"); | |
Assert.AreEqual(1, results.Keys.Count); | |
} | |
} | |
} | |
public class Foo | |
{ | |
public string Id { get; set; } | |
public Dictionary<string, DateTimeOffset> Dates { get; set; } | |
public Foo() | |
{ | |
Dates = new Dictionary<string, DateTimeOffset>(); | |
} | |
} | |
public class FooTransformer : AbstractTransformerCreationTask<Foo> | |
{ | |
public class Result | |
{ | |
public List<string> Keys { get; set; } | |
} | |
public FooTransformer() | |
{ | |
TransformResults = foos => from foo in foos | |
select new | |
{ | |
Keys = foo.Dates.OrderBy(x => x.Value).Select(x => x.Key).ToList() | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment