Created
July 1, 2016 20:54
-
-
Save JudahGabriel/fef01e0b0784927ba256f318726a170f 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
// 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 | |
{ | |
RecipeId = recipe.Id | |
Name = recipe.Name, | |
PictureUrl = recipe.PictureUrl, | |
Categories = categories.Select(c => c.Name).ToList(), | |
ChefEmail = chef.Email, | |
ChefName = chef.Name, | |
Ingredients = ingredients.ToList(), | |
Comments = comments.ToList() | |
}; | |
return recipeViewModel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment