如何插入具有多个具有类别的图像的产品 [英] How to insert a Product with multiple images having a category

查看:69
本文介绍了如何插入具有多个具有类别的图像的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为的表:类别

第二个名为:产品

第三个名为:< b> ProductImages



产品详情:

例如诺基亚N70产品详细信息:





类别
- >诺基亚

产品 ---> N-70

产品图片网址 - > image1.jpg,image2.jpg,image3.jpg



我想在类别表中插入名为Nokia的类别。我做得很好。

现在我想在Products表中插入一个产品,但是在这里我遇到了一个问题,我可以插入一个具有这些属性的记录。



1.产品名称 - >诺基亚N70

2.分类名称 - >诺基亚

3.价格 - > 1234

4.屏幕尺寸 - > A X B

5. ImageUrl - > abcd.jpg

6. ProductId - > 1



但是我想要插入多个图像,我希望实体框架创建一个名为ProductImages的表,它将存储针对该产品的多个图像。我的意思是我想在ProductImages表中使用ProductId作为外键。产品的所有属性都应保存在Product表中,但图像URL应保存在另一个名为ProductImages的表中。

ProductImages with two attribue,1。ProductId(作为foriegn Key)2。ImageUrl在此方式。





表:产品

1.产品名称 - >诺基亚N70

2.分类名称 - >诺基亚

3.价格 - > 1234

4.屏幕尺寸 - > A X B

5. ProductId - > 1



表: 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



如果有任何想法,请通知我,我会非常感谢你仁慈的行为。

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.

推荐答案

您可以使用以下三种方法之一来实现您的设计与实体框架

1-schema first br />
2型号首先

3码首先



选择你喜欢的每一个,当然每个人都有它的首选项,请检查链接:

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 [ ^ ]



我建议使用CodeFirst,因为它易于启动且易于学习。
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.


这篇关于如何插入具有多个具有类别的图像的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆