Skip to content

Instantly share code, notes, and snippets.

View JudahGabriel's full-sized avatar

Judah Gabriel Himango JudahGabriel

View GitHub Profile
// Query for the honey glazed salmon recipe
// and transform it into a RecipeViewModel.
var recipeViewModel = ravenSession.Query<Recipe>()
.TransformWith<RecipeViewModelTransformer, RecipeViewModel>()
.Where(r => r.Name == "Sweet honey glazed salmon")
.First();
/// <summary>
/// RavenDB Transformer that turns a Recipe into a RecipeViewModel.
/// </summary>
public class RecipeViewModelTransformer : AbstractTransformerCreationTask<Recipe>
{
public RecipeViewModelTransformer()
{
TransformResults = allRecipes => from recipe in allRecipes
let chef = LoadDocument<Chef>(recipe.ChefId)
let comments = LoadDocument<Comment>(recipe.CommentIds)
// 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);
// Theoretical LINQ code to perform a JOIN against a relational database.
public RecipeViewModel GetRecipeDetails(string recipeId)
{
var recipeViewModel = from recipe in dbContext.Recipes
where recipe.Id == 42
join chef in dbContext.Chefs on chef.Id equals recipe.ChefId
let ingredients = dbContext.Ingredients.Where(i => i.RecipeId == recipe.Id)
let comments = dbContext.Comments.Where(c => c.RecipeId == recipe.Id)
let categories = dbContext.Categories.Where(c => c.RecipeId == recipeId)
select new RecipeViewModel
/// <summary>
/// View model for a Recipe. Contains everything we want to display on the Recipe details UI page.
/// </summary>
public class RecipeViewModel
{
public string RecipeId { get; set; }
public string Name { get; set; }
public string PictureUrl { get; set; }
public List<Ingredient> Ingredients { get; set; }
public List<string> Categories { get; set; }
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
static double items[1000000];
int i = 0;
for (i = 0; i < 1000000; i++)
{