数据库设计帮助。多对多创建关联表,对吗?

发布于 2024-09-06 16:48:56 字数 433 浏览 0 评论 0原文

我正在为我的应用程序设计一个非常简单的数据库,其配置如下:

Employee
Carnet
Name
LastName

Area
Name

Document
ID
Employee (FK)
Project (FK)

Project
ID
Company (FK)
Title

Company
Name
CEO (FK)
NIT

Person
Carnet
Name
Lastname

现在这个问题的要点是,一个区域可以有许多文档;并且一个文档可以属于多个区域

据我所知,这创建了第三个关系表,对吗?

如果我要使用 Linq-to-SQL 作为访问数据库的唯一工具,该表中会包含什么内容,这是否能够工作。

I'm designing a very simple database for my application and it's configured like this:

Employee
Carnet
Name
LastName

Area
Name

Document
ID
Employee (FK)
Project (FK)

Project
ID
Company (FK)
Title

Company
Name
CEO (FK)
NIT

Person
Carnet
Name
Lastname

Now the gist of this question is, an Area can have many Document; and a Document can belong to many Area.

This I'm told, creates a third relationship table, correct?

What would go in that table and would this be able to work if I'm going to be using Linq-to-SQL as the only tool for accessing my database.

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

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

发布评论

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

评论(1

北凤男飞 2024-09-13 16:48:56

是的...您将有一个名为 AreaDocuments 的表,其中包含名为 AreaID 和 DocumentId 的列。这种关系是 M x N,其中 M 个实例可以关联到 N 个实例,反之亦然。

示例数据:

AreaId      DocumentId
1           1
1           2
2           1
2           2

如何在代码中处理它:

Document document1 = new Document();
document1.Id = 1;
document1.Title = "Whatever";

Document document2 = new Document();
document2.Id = 2;
document2.Title = "Whatever";

Area area1 = new Area();
area1.Documents.Add(document1);
area1.Documents.Add(document2);

Area area2 = new Area();
area2.Documents.Add(document1);
area2.Documents.Add(document2);

此链接 如何使用 Linq to Sql 实现多对多关系? 可以提供有关在 LINQ to 中使用这种关系的更多信息SQL。

Yes... You'd have a table called AreaDocuments with columns called AreaID and DocumentId. This kind of relationship is M x N where M instances can be associated to N instances and vice-versa.

Sample data:

AreaId      DocumentId
1           1
1           2
2           1
2           2

How to handle it in code:

Document document1 = new Document();
document1.Id = 1;
document1.Title = "Whatever";

Document document2 = new Document();
document2.Id = 2;
document2.Title = "Whatever";

Area area1 = new Area();
area1.Documents.Add(document1);
area1.Documents.Add(document2);

Area area2 = new Area();
area2.Documents.Add(document1);
area2.Documents.Add(document2);

This link How to implement a many-to-many relationship using Linq to Sql? can provide more information about using this kind of relationship in LINQ to SQL.

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