2

我有两个表:Products(ProductID, ProductName)和 之间的Categories(CategoryID, CategoryName) 多对多关系ProductsCategories ProductsCategories(ProductID, CategoryID)

如何实现一个视图,使用户能够使用 Asp.Net Mvc 和 LINQ to SQL添加和编辑具有多个类别的产品?

4

1 回答 1

0

Since LINQ to SQL only supports a strict 1:1 mapping with your database you would have to make a link table. This would look something like...

[ProductCategories]
ID
ProductID (FK)
CategoryID (FK)

Then for every relationship of product to categories you would just make a new ProductCategories entity and insert it. So given the data...

Products
ID Name
1 Apple
2 XBOX 360

Categories
ID Name
1 Produce
2 Electronics
3 Game Systems

Your link table would look like

ProductCategories
ID ProductID CategoryID
1 1 1
2 2 2
3 2 3

于 2009-06-21T13:56:36.273 回答