<class name="Customer,DomainModel" table="Customer"> <id name="CustomerId" column="CustomerId" type="Int32" unsaved-value="0"> <generator class="native"></generator> </id> <property name="Firstname" column="Firstname" type="string" length="50" not-null="false"></property> <property name="Lastname" column="Lastname" type="string" length="50" not-null="false"></property> <bag name="Orders" table="[Order]" generic="true" inverse ="false" cascade ="All" > <key column="Customer"/> <span style="color: #ff0000;"> <!--這里面 one-to-many 和 composite-element都能實現一對多,他們之間有什么區別--></span> <one-to-many class="DomainModel.Entities.Order,DomainModel" /> <!--composite-element class="DomainModel.Entities.Order,DomainModel"> <parent name="Customer"/> <property name="OrderId" column="OrderId" type="Int32"/> <property name="OrderDate" column ="OrderDate" type="DateTime" not-null="false"/> </composite-element--> </bag> </class>
2 回答

慕蓋茨4494581
TA貢獻1850條經驗 獲得超11個贊
前者更多的是表現關聯關系,后者更多的是表現從屬關系
有很多需求這種都可以實現,只是說體現不同的想法了。
比如說一個人有很多郵箱,那么這個郵箱就是從屬于這個人,那么同樣,你仍然可以認為,這兩種是關聯關系而已。

一只甜甜圈
TA貢獻1836條經驗 獲得超5個贊
使用<composite-element>標簽定義component集合,
Component是一個被包含的對象,它作為值類型被持久化,而非一個被引用的實體?!癱omponent(組件)”這一術語指的是面向對象的合成概念.
添加回答
舉報
0/150
提交
取消