Linq To SQL:关联建模

发布于 2024-07-23 03:49:25 字数 248 浏览 4 评论 0原文

我有三个表“项目”、“用户”和“项目成员”。 ProjectMembers 表是一个映射表,只有两列 ProjectId 和 UserId。

在我的对象模型中,我有两个类“项目”和“用户”。 Project 类有一个属性 IEnumerable成员

我正在使用外部 xml 映射文件来将 linq 映射到 sql 关联。 我能够获取项目和用户数据,但我不知道如何映射成员关联。

I have three tables Projects, Users and ProjectMembers. The ProjectMembers table is a mapping table and has only two columns ProjectId and UserId.

In my object model i have two classes Project and User. The Project class has a property IEnumerable<User> Members

I am using an external xml map file for mapping linq to sql associations. I am able to get the Project and the User data but I dont know how to map the Members association.

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

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

发布评论

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

评论(1

深爱成瘾 2024-07-30 03:49:25

这听起来像是多对多映射(项目 <-> 用户)。

在这种情况下,您将在使用 Linq To SQL 时遇到问题。 长话短说,它并不真正支持这种映射。 您可以在 google 上找到多种解决方法,其中之一是更改分部类以分别提供对 Project 和 User 类上的 Members/Projects 集合的访问。

例如 http://www .iaingalloway.com/2015/06/many-to-many-relationships-in-linq-to-sql.html

This sounds like a Many-to-Many mapping (Projects <-> Users).

In which case you are going to run into problems using Linq To SQL. To cut a long story short it does not really support that mapping. There are several workarounds which you can find on google, one of which is altering the partial class to provide the access to the Members/Projects collection on the Project and User classes respectively.

e.g. http://www.iaingalloway.com/2015/06/many-to-many-relationships-in-linq-to-sql.html

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