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++) | |
{ |
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
// 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
// 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
/// <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 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
// Query for all recipes and transform them into RecipeViewModels. | |
var allRecipeViewModels = ravenSession.Query<Recipe>() | |
.TransformWith<RecipeViewModelTransformer, RecipeViewModel>() | |
.ToList(); |
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
var recipeViewModel = new RecipeViewModel | |
{ | |
Name = "Sweet honey glazed salmon", | |
RecipeId = "recipes/1", | |
PictureUrl = "http://tastyrecipesyum.com/recipes/1/profile.jpg", | |
Categories = new List<string> { "salmon", "fish", "seafood", "healthy" }, | |
ChefName = "Swei D. Sheff", | |
ChefEmail = "[email protected]", | |
Comments = new List<Comment> { new Comment { Name = "Dee Liteful", Content = "I really enjoyed this dish!" } }, | |
Ingredients = new List<Ingredient> { new Ingredient { Name = "salmon fillet", Amount = "5 ounce" } } |
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
// Listen for changes to Recipes. | |
// When that happens, update the corresponding RecipeViewModel. | |
ravenStore | |
.Changes() | |
.ForDocumentsOfType<Recipe>() | |
.Subscribe(docChange => this.UpdateViewModelFromRecipe(docChange.Id)); |
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 index that is run automatically whenever a Recipe changes. For every recipe, the index outputs a RecipeViewModel. | |
/// </summary> | |
public class RecipeViewModelIndex : AbstractIndexCreationTask<Recipe> | |
{ | |
public RecipeViewModelIndex() | |
{ | |
Map = allRecipes => from recipe in allRecipes | |
let chef = LoadDocument<Chef>(recipe.ChefId) | |
let comments = LoadDocument<Comment>(recipe.CommentIds) |
OlderNewer