Database Design Product Recipe Ingredients -


i trying create simple application , needed aspect of db design. attempting ef code first, need in order know goes in classes , how link via navigation properties.

i need have structure, can query this

recipe margarita (product) "tomato sauce","cheese"

product id pk desc

recipe id pk prodid fk ingid fk

ingredients id pk desc

i not sure how create table show me product many ingredients? current structure wont able many ingredients against product?

i stuck , cannot head around it.

i misunderstanding question, think you're asking how relate dynamic number of ingredients recipe. i'd in sql server:

create table recipes (     id int primary key identity(1, 1),     name nvarchar(max) )  create table ingredients (     id int primary key identity(1, 1),     desc nvarchar(max) )  create table ingredientslist (     id int primary key identity(1, 1),     recipeid int foreign key references recipes(id),     ingredientid int foreign key references ingredients(id) )  insert recipes (name) values  ('margarita pizza')  insert ingredients (desc) values ('tomato sauce'), ('cheese')  declare @id int = (select id recipes name = 'margarita pizza')  insert ingredientslist (recipeid, desc) select      @id,     a.id ingredients a.desc in ('tomato sauce', 'cheese')  select a.name, c.desc recipes join ingredientslist b on a.id = b.recipeid join ingredients c on b.ingredientid = c.id 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -