Skip to content

Instantly share code, notes, and snippets.

@brunomlopes
Created September 26, 2017 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomlopes/833e176ae2282309b5ddd29c98fbab4d to your computer and use it in GitHub Desktop.
Save brunomlopes/833e176ae2282309b5ddd29c98fbab4d to your computer and use it in GitHub Desktop.
Sample for extending an index from client-side for ravendb 4.0
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