Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Query for the honey glazed salmon recipe
// and .Include the related Chef and Comment objects.
var recipe = ravenSession.Query<Recipe>()
.Include(r => r.ChefId)
.Include(r => r.CommentIds)
.Where(r => r.Name == "Sweet honey glazed salmon")
.First();
// No extra DB call here; it's already loaded into memory via the .Include calls.
var chef = ravenSession.Load<Chef>(recipe.ChefId);
// Ditto.
var comments = ravenSession.Load<Comment>(recipe.CommentIds);
var recipeViewModel = new RecipeViewModel
{
RecipeId = recipe.Id,
Name = recipe.Name,
PictureUrl = recipe.PictureUrl,
ChefEmail = chef.Email,
ChefName = chef.Name,
Comments = comments.ToList(),
Ingredients = recipe.Ingredients,
Categories = recipe.Categories
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment