一对多链接关系的唯一性是什么意思?[英] What does it mean for a One-to-many Link relation to be Unique?

本文是小编为大家收集整理的关于一对多链接关系的唯一性是什么意思?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在 Linq 对象关系 (O/R) 映射器中的两个表之间划了一条线:

 Order                  Customer
--------------           ---------------
| OrderID    |           | CustomerID  |
| CustomerID |♦---------˃| ...         |
|            |           |             |
--------------           ---------------

注意:或者可能是

 Order                    Customer
--------------           ---------------
| OrderID    |           | CustomerID  |
| CustomerID |˂---------♦| ...         |
| ...        |           |             |
--------------           ---------------

我不确定;它让我可以双向拖动.

  • 第一个问题,什么是箭头,什么是菱形?

假设第二个图,Association 的 cardinality 被创建为 OneToMany.这是有道理的,因为:

  • 一个客户
  • 有许多订单

但让我感到困惑的是 Association.Unique (布尔)属性.它默认为 false.这是有道理的,因为它是一个 OneToMany 关联.Order.CustomerID 不能是唯一的,否则就不是 OneToMany 关联,而是 OneToOne.

然后我可以将 OneToMany Unique 属性更改为 true.这是没有意义的,所以我得出结论,Unique 不适用于 Order.CustomerID,而是适用于 Customer.CustomerID.但是该图已经表明 Customer.CustomerID 是 主键.当然它是唯一的,它是一个主键.

但是 Unique 属性没有设置.这是没有意义的,所以我得出结论, Unique ness 并不意味着任何一个表.

  • 第二个问题,Unique是什么意思?

    <块引用>

    指定外部目标列是否具有唯一性约束

  • 第三个问题:parent和child是什么?

再次假设第二个图表:

Customers.CustomerID ♦------------> Orders.CustomerID

我以 Customers 表为父.它是拥有客户意义的人.你想改变一个客户,你走到父母那里.

与此同时,子 Orders 表出现并想要引用一个 Customer.

     Parent(diamond)                     Child(arrowhead)
====================                     =================
Customers.CustomerID (PK) ♦------------> Orders.CustomerID (FK)

除了当我查看关联的 Parent 和 Child 属性时:

子属性

  • Name: Orders

父属性

  • Name: Customer

他们想在 "child" 上创建一个名为 Orders 的属性.不不不.子是命令.他们想向父级添加一个名为 Customer 的属性.不不不.父级是客户.

这意味着我必须把它倒过来,而 parent 和 child 这两个术语与我的想法完全相反:

      Child(diamond)                     Parent(arrowhead)
====================                     =================
Customers.CustomerID (PK) ♦------------> Orders.CustomerID (FK)

到了这个时候,我想把我的大脑炸飞;而是花 35 分钟在 Stackoverflow 上编写问题;而不是继续对着我的电脑尖叫.

帮助.

推荐答案

关于问题 2 - Unique 属性可能表示该关系是 OneToOne 关系.

即使直接在 sql 数据库中也没有特定的 OneToOne 关系.相反,只有一个外键可以将一个表中的键导出到另一个表.因此,外键关系始终是一对多的.在包含导出键的表上使用附加约束,可以使关系事实上是一对一的.但这样做并不会改变外键关系,而只是对外键表中的数据应用附加条件.

关于问题3:属性名称意味着子对象(Order)将有一个名为Customer的属性,可用于获取父对象的实例.并且父对象将有一个名为 Orders 的属性,可用于为客户获取子对象.

本文地址:https://www.itbaoku.cn/post/1556876.html

问题描述

i drug a line between two tables in the Linq Object Relational (O/R) mapper:

 Order                  Customer
--------------           ---------------
| OrderID    |           | CustomerID  |
| CustomerID |♦---------˃| ...         |
|            |           |             |
--------------           ---------------

Note: Or perhaps it was

 Order                    Customer
--------------           ---------------
| OrderID    |           | CustomerID  |
| CustomerID |˂---------♦| ...         |
| ...        |           |             |
--------------           ---------------

i'm not sure; it lets me drag both ways.

  • First question, what's the arrowhead, and what's the diamond?

Assuming the second diagram, the cardinality of the Association was created as OneToMany. This makes sense, since:

  • one customer
  • has many orders

But what confuses me is the Association.Unique (Boolean) property. It defaults to false. This makes sense because it's a OneToMany association. Order.CustomerID cannot be unique, otherwise it wouldn't be a OneToMany association, it would be OneToOne.

But then i'm allowed to change the OneToMany Unique property to true. This makes no sense, so i conclude that Unique ness doesn't apply to Order.CustomerID, but instead to Customer.CustomerID. But the diagram already indicates Customer.CustomerID is a Primary Key. Of course it's unique, it's a primary key.

But the Unique property isn't set. This makes no sense, so i conclude that Unique ness doesn't mean either table.

  • Second question, what does Unique mean?

    Specifies whether the foreign target columns have a uniqueness constraint

  • Third question: What is parent and child?

Assuming, again, the second diagram:

Customers.CustomerID ♦------------> Orders.CustomerID

i take Customers table to be a parent. It's the one who owns what it means to be a customer. You want to change something about a customer, you walk to the parent.

Meanwhile, the child Orders table comes along and wants to reference a Customer.

     Parent(diamond)                     Child(arrowhead)
====================                     =================
Customers.CustomerID (PK) ♦------------> Orders.CustomerID (FK)

Except that when i look at the association's Parent and Child properties:

Child property

  • Name: Orders

Parent property

  • Name: Customer

They want to create a property on the "child" called Orders. No, no, no. The child is orders. And they want to add a property to the parent called Customer. No, no no. The parent is a customer.

That means i must have it backwards, and the terms parent and child are the exact opposite of what i thought:

      Child(diamond)                     Parent(arrowhead)
====================                     =================
Customers.CustomerID (PK) ♦------------> Orders.CustomerID (FK)

And by this time i want to blow my brains out; and instead spend 35 minutes authoring a question on Stackoverflow; rather than continuing to scream at my computer.

Help.

推荐答案

Regarding question 2 - The Unique property probably signifies that the relation is a OneToOne relation.

Even directly in a sql database there is no specific OneToOne relationship. Rather there is simply the foreign key where a key in one table can be exported to another table. As such a foreign key relationship is ALWAYS one to many. Using additional constraints on the table containing the exported key, the relationship can be made de facto one to one. But doing that doesn't change the foreign key relation, rather it simply applies additional conditions on the data in the foreign key table.

Regarding question 3: The property names mean that the child object (Order) will have a property called Customer which can be used to get an instance of the parent object. And the parent object will have a property called Orders which can be used to fetch children for the customer.