ASP.Net MVC HABTM 协会

发布于 2024-08-15 15:54:11 字数 287 浏览 3 评论 0原文

当尝试定义与我的两个模型的 HABTM 关联时,我一定错过了一些东西。我有一个“产品”表、一个“类别”表和一个“ProductsCategories”连接表。在 SQL Server 中,我定义连接表上表之间的关系。但是,当我创建 LINQ to SQL 模型“Product”时,我得到“Product.ProductCategories -> ProductCategory,ProductsCategory.Product -> Product”是否可以在 asp.net mvc 中定义一个给我 Product 的关系.类别还是类别.产品?

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 Relationship 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栩栩如生 2024-08-22 15:54:11

在这个问题上肯定有人比我更聪明,但如果您使用 DBML 文件自动生成数据库模型,我不知道如何[自动]执行此操作。了解可以使用 Product.ProductCategories.CategoryCategory.ProductCategories.Product 后,您可以为 Product 和 Category 创建部分类,定义名为 Products 和 Categories 返回 Product.ProductCategories.Category 和 Category.ProductCategories.Product。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文