Created
July 1, 2016 20:55
-
-
Save JudahGabriel/76b4a8ac27d800b5ba277c65c52120da to your computer and use it in GitHub Desktop.
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
// 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