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

查看:111
本文介绍了一对多链接关系是唯一的意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

注意:也许是

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

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

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

  • 第一个问题,箭头是什么,钻石是什么?

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

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

  • 一个客户
  • 很多个订单
  • one customer
  • has many orders

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

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.

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

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.

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

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

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

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

  • 第三个问题:父母孩子是什么?

  • Third question: What is parent and child?

    再次假设第二张图:

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

    我将Customers表作为父级.拥有成为客户意味着什么的人.您想更改有关客户的某些信息,然后步行去找父母.

    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.

    与此同时,子Orders表也出现了,并希望引用Customer.

    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:

    子级属性

    • Name:Orders

    父级财产

    • Name:Customer

    他们想在子" 上创建一个名为Orders的属性.不不不.子命令.他们想为父级添加一个名为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.

    这意味着我必须倒退它,并且 parent child 这两个词与我的想法完全相反:

    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)
    

    到这个时候,我想动脑筋;而是花35分钟编写有关Stackoverflow的问题;而不是继续对我的电脑大喊大叫.

    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.

    帮助.

    推荐答案

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

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

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

    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.

    关于问题3:属性名称表示子对象(订单)将具有一个名为Customer的属性,该属性可用于获取父对象的实例.父对象将具有一个名为Orders的属性,可用于为客户获取子代.

    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.

    这篇关于一对多链接关系是唯一的意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆