Skip to content

Instantly share code, notes, and snippets.

@JudahGabriel
Created July 1, 2016 21:03
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 JudahGabriel/082eb9df01880ecb3556accb4353b081 to your computer and use it in GitHub Desktop.
Save JudahGabriel/082eb9df01880ecb3556accb4353b081 to your computer and use it in GitHub Desktop.
/// <summary>
/// RavenDB index that is run automatically whenever a Recipe changes. For every recipe, the index outputs a RecipeViewModel.
/// </summary>
public class RecipeViewModelIndex : AbstractIndexCreationTask<Recipe>
{
public RecipeViewModelIndex()
{
Map = allRecipes => from recipe in allRecipes
let chef = LoadDocument<Chef>(recipe.ChefId)
let comments = LoadDocument<Comment>(recipe.CommentIds)
select new RecipeViewModel
{
RecipeId = recipe.Id,
Name = recipe.Name,
PictureUrl = recipe.PictureUrl,
Ingredients = recipe.Ingredients,
Categories = recipe.Categories,
ChefEmail = chef.Email,
ChefName = chef.Name,
Comments = comments
};
StoreAllFields(Raven.Abstractions.Indexing.FieldStorage.Yes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment