Skip to content

Instantly share code, notes, and snippets.

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