Hi! I need to make a conclusion with DB using EF. The user adds the products that he has in the refrigerator one by one by clicking on the "Add product" button. These products are added to the array. List<string> productsList = new List<string>(); and I plan on sorting out this array to output recipes in which there are these products. But the catch is that there is a table with Products and a table with Recipes, and since one product can have many recipes and there can be many products in recipes I link them through the third Table RecipieIngredients in which they are linked by their id. The problem is that I can not understand how I can implement a search for recipes by product and then display a list of recipes?
namespace WindowsFormsApp1 { using System; using System.Collections.Generic; public partial class Ingredients { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Ingredients() { this.RecipeIngredient = new HashSet<RecipeIngredient>(); } public int Id { get; set; } public string Name { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } } } Recipe
namespace WindowsFormsApp1 { using System; using System.Collections.Generic; public partial class Recipe { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Recipe() { this.RecipeIngredient = new HashSet<RecipeIngredient>(); } public int Id { get; set; } public string Name { get; set; } public Nullable<int> Prop_Time { get; set; } public string Instructions { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } } } RecipeIngredient
namespace WindowsFormsApp1 { using System; using System.Collections.Generic; public partial class RecipeIngredient { public int Id { get; set; } public int RecipeId { get; set; } public int IngredientId { get; set; } public virtual Ingredients Ingredients { get; set; } public virtual Recipe Recipe { get; set; } } } 