views:

1052

answers:

2

I have two Tables: Products(ProductID, ProductName) and Categories(CategoryID, CategoryName) with a many-to-many relationship between Products and Categories ProductsCategories(ProductID, CategoryID)

How Can I Implement a view that enables a user to Add and Edit one product with many categories using Asp.Net Mvc and LINQ to SQL?

+1  A: 

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

Chad Moran
Thanks for help but My Question ISHow Can I Implement a view that enable user to add and Edit one prodcut to many category Using ASP.NET Mvc and LINQ TO SQL
MVCGUY
A: 

Take a look at this post

Oleiro