I am building a project of editing an existing recipe
Please note--- Each recipe can have more than one ingredients group (-this is my point in building this project)
- Recipe table (recipe ID, name, etc.)
- Linking table of ingredients group for each recipe ChartsForOneRecipe (group ID, name of the group example: (to base,to the sauce ))
- There is Ingredients table (ID, and name)
- A table which has a List of ingredients for all the ingredients groups ingredientsInChart (ID for every ingredient , ID to which ingredient group it belongs , ingredient ID, quantity,)
Does anyone have an idea how do I get out the names of the ingredients associated with one ingredient group ? In C # MVC of course not in SQL
my questions are:
how can I do this in one function ? how to write it correctly that it will work. if it's possible not to copy or create new tables.
Note I dont have any FK in my tables yet. By the end I need to get from db the ingredients groups for each recipe. and all the ingredients groups are in one table and have only the ID of the ingredients', Id of the groups and not the name of it.
I have started Wrote this functions :
in Recipes controller:
mydata db = new data()
private List<ChartsForOneRecipe> lchart;
A function that returns all the groups which belongs to a specific recipe the func works well
[HttpGet] public IHttpActionResult GetTheNamesOfChartsByRecipeId(int RecipeId) { lchart = db.ChartsForOneRecipe.Where(ch => ch.recipeId == RecipeId).ToList(); return base.Ok(lchart); }
A function that returns all the ingredients in a specific group of ingredients and it didn't work
[HttpGet]//return all ingredients in a chart by getting chartid public IHttpActionResult GetAlltheIngredientsInChart(int ChartId) { var q = from ing in db.Ingredients from ingch in db.IngredientsInChart where (ing.ingredientID == ingch.ingredientsInChartId && ingch.chartId == ChartId) select new { ing.ingredientID, ing.name }; return Ok(q);
}