开发者

ASP.Net MVC HABTM Association

开发者 https://www.devze.com 2022-12-14 16:21 出处:网络
I must be missing something, when trying to define a HABTM association with 2 of my models.I have a \"Product\" table, and a \"Category\" table, and a \"ProductsCategories\" join table.In SQL Server,

I must be missing something, when trying to define a HABTM association with 2 of my models. I have a "Product" table, and a "Category" table, and a "ProductsCategories" join table. In SQL Server, I am defining the Relationsh开发者_开发百科ip between the tables on the join table. However, when I create the LINQ to SQL model "Product," I get "Product.ProductCategories -> ProductCategory, ProductsCategory.Product -> Product" Is it possible in asp.net mvc to define a relationship that would give me Product.Categories or Category.Products?


Someone is surely wiser than me on the subject, but I don't know a way of doing this [automatically] if you are using a DBML file to autogenerate your database model. By knowing you can use Product.ProductCategories.Category and Category.ProductCategories.Product, you can create partial classes for Product and Category that define properties named Products and Categories which return Product.ProductCategories.Category, and Category.ProductCategories.Product.

0

精彩评论

暂无评论...
验证码 换一张
取 消