我的模型包含以下实体:
<cf:entity name="Order" cfom:bindingList="false">
<!--persistenceIdentity is true, because the corresponding column for this property must be auto incremented by the database.-->
<cf:property name="Id" typeName="ulong" key="true" persistenceIdentity="true" cfps:hint="CLUSTERED" />
<!-- composition relation -->
<cf:property name="Orderlines" typeName="{0}.OrderlineCollection" cascadeDelete="Before" cascadeSave="After" />
<cf:method name="Save">
<cf:rule typeName="transaction" transactionType="TransactionScope" timeout="00:60:00" scopeOption="Required" />
</cf:method>
</cf:entity>
<cf:entity name="Orderline" cfom:bindingList="false">
<!--persistenceIdentity is true, because the corresponding column for this property must be auto incremented by the database.-->
<cf:property name="Id" typeName="ulong" key="true" persistenceIdentity="true" cfps:hint="CLUSTERED" />
<!-- Relation back to indicate an 1-to-n composition relationship. -->
<cf:property name="Order" typeName="{0}.Order" />
</cf:entity>
我有以下代码:
Order order = new Order();
Orderline orderline = new Orderline();
order.Orderlines.Add(orderline); // ERROR
order.Save(); // Save the order and its orderlines
将实体添加到集合时出现错误,因为 Id 属性包含值 0。我该如何解决这个问题?我不想在将实体添加到集合之前保存它。