Пример #1
0
            public PeopleByEmail()
            {
                Map = people => from person in people select new
                {
                    _ = CreateField("Email", PeopleUtil.CalculatePersonEmail(person.Name, person.Age), true, true),
                };
                AdditionalSources = new Dictionary <string, string>
                {
                    {
                        "PeopleUtil",
                        @"
using System;
using NodaTime;
namespace My.Crazy.Namespace
{
    public static class PeopleUtil
    {
        public static string CalculatePersonEmail(string name, uint age)
        {
            //The code below intention is just to make sure NodaTime is compiling with our index
            return $""{name}.{Instant.FromDateTimeUtc(DateTime.Now.ToUniversalTime()).ToDateTimeUtc().Year - age}@ayende.com"";
        }
    }
}
"
                    }
                };
            }
Пример #2
0
 public void CanCompileIndexWithExtensions()
 {
     using (var store = GetDocumentStore())
     {
         store.ExecuteIndex(new PeopleByEmail());
         using (var session = store.OpenSession())
         {
             var p = new Person()
             {
                 Name = "Methuselah", Age = 969
             };
             session.Store(p);
             session.SaveChanges();
             WaitForIndexing(store);
             var query = session.Query <PeopleByEmail.PeopleByEmailResult, PeopleByEmail>()
                         .Where(x => x.Email == PeopleUtil.CalculatePersonEmail(p.Name, p.Age)).OfType <Person>().Single();
         }
     }
 }