0

I'm not sure how to set up this database in Entity Framework. I have theese models:

public class Recipe
    {
        public int RecipeId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Difficulty { get; set; }
        public IEnumerable<Ingredient> Ingredients { get; set; }

    }

    public class Ingredient
    {
        public int IngredientId { get; set; }
        public string Name { get; set; }
        public IEnumerable<Recipe> Recipes { get; set; }

    }

But I need to add measure(unit) and amount. It should be in litre and gram. Where should I add this? My thoughts at the moment are:

  • A third entity. But how should i set that up?
  • Put it in Ingredient but then I cant reuse the Ingredient on another Recipe

Everything will be displayed in a ASP.NET MVC project later.

  • Whenever I've done this, a recipe would include a collection of `Step` classes, each of which can have some instructions (string), one or more ingredients, and amounts (by weight, volume, or number) of those ingredients. You can wrap ingredients if you want into `StepIngredients` or something which can contain an ingredient and an amount. – DrewJordan Dec 22 '16 at 18:08
  • See [this article](https://lostechies.com/jimmybogard/2014/03/12/avoid-many-to-many-mappings-in-orms/). You would replace CourseInstructor with RecipeIngredient and add properties for measure and amount. Or see [this popular question](http://stackoverflow.com/questions/7050404/create-code-first-many-to-many-with-additional-fields-in-association-table) about many to many with additional fields. – Steve Greene Dec 22 '16 at 18:24
  • Thanks guys. Worked with a third table. – user3775283 Dec 23 '16 at 10:22

0 Answers0