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 transform it into a RecipeViewModel. | |
var recipeViewModel = ravenSession.Query<Recipe>() | |
.TransformWith<RecipeViewModelTransformer, RecipeViewModel>() | |
.Where(r => r.Name == "Sweet honey glazed salmon") | |
.First(); |
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
/// <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) |
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); |
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
// 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 |
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
/// <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; } |
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
#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++) | |
{ |
NewerOlder