-
-
Save brunomlopes/833e176ae2282309b5ddd29c98fbab4d to your computer and use it in GitHub Desktop.
Sample for extending an index from client-side for ravendb 4.0
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
public class Checkin_ByDay : AbstractIndexCreationTask<Checkin> | |
{ | |
public class Result | |
{ | |
public string Id { get; set; } | |
public int Count { get; set; } | |
public string[] Names { get; set; } | |
} | |
public Checkin_ByDay() | |
{ | |
Map = entities => from entity in entities | |
select new | |
{ | |
Count = entity.Count, | |
Day = entity.When.Date, | |
Names = new[] { entity.Name.NamePlusExt("plus") } // using extension methods on the fields | |
}.AppendCommonProperty(); // adding common properties on a resulting object | |
StoreAllFields(FieldStorage.Yes); | |
AdditionalSources = new Dictionary<string, string>() | |
{ | |
{"RandomClass", @" | |
using System; | |
namespace My.Crazy.Namespace { | |
public static class RandomClass { | |
public static object AppendCommonProperty(this object test) | |
{ | |
var x = (dynamic)test; | |
x.Common = true; | |
return x; | |
} | |
public static string NamePlus(string name, string plus){ | |
return name + plus; | |
} | |
public static string NamePlusExt(this string name, string plus){ | |
return name + plus; | |
} | |
} | |
} | |
"} | |
}; | |
} | |
} | |
public class Checkin | |
{ | |
public string Id { get; set; } | |
public string Name { get; set; } | |
public DateTimeOffset When { get; set; } | |
public int Count { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment