Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a table named: Categories
2nd table named: Products
3rd Table named: ProductImages

A product details:
For example Nokia N70 Product Details:


Category
--> Nokia
Product ---> N-70
Product Images Url --> image1.jpg, image2.jpg, image3.jpg

I want to insert a category named Nokia in categories table. I have done this well.
Now I want to insert a product in Products table, but here I am facing a problem, I can insert a single record having these attributes.

1. Product Name --> Nokia N70
2. Category Name --> Nokia
3. Price --> 1234
4. Screen Size --> A X B
5. ImageUrl --> abcd.jpg
6. ProductId -- > 1

But I want to insert multiple images, I want entity framework to create a table named ProductImages which will store multiple images against this product. I means I want to use ProductId as a foreign key in ProductImages table. All attributes of product should be saved in Product table but images urls should be saved in another table having named ProductImages
ProductImages with be two attribue, 1. ProductId (As a foriegn Key) 2. ImageUrl in this way.


Table: Products
1. Product Name --> Nokia N70
2. Category Name --> Nokia
3. Price --> 1234
4. Screen Size --> A X B
5. ProductId -- > 1

Table: ProductImages
1. Id (AutoGenerated) - 1
2. ProductId -- > 1
3. ImageUrl image1.jpg

1. Id (AutoGenerated) - 2
2. ProductId -- > 1
3. ImageUrl image2.jpg

1. Id (AutoGenerated) - 3
2. ProductId -- > 1
3. ImageUrl image3.jpg

If any one having idea, please inform me, I will be very thankful to you for this act of kindness.
Posted

1 solution

You can use one of the three ways to implement your design with entity framwork
1-schema first
2-model first
3-code first

select each one you prefer, off course every one has it's preference, check the links:
http://msdn.microsoft.com/en-us/data/hh134698.aspx[^]

https://www.google.com/#q=entity+framework+model+first[^]

http://msdn.microsoft.com/en-us/data/jj206878.aspx[^]

I suggest CodeFirst because it's easy to start and easy to learn.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900