在我的模型中,我使用bigint(ulong)作爲實體鍵的類型。 0值必須用於空鍵。 外鍵的列不能爲空,因爲在我的方法中,我只想檢查值0而不是null。 一切工作正常,除了刪除其他實體引用的相關實體。當刪除相關實體時,CodeFluent嘗試更新一個類型爲bigint的不可爲空的外鍵
這裏是我的模型:
<cf:entity name="Customer" 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" />
<cf:property name="Name" typeName="string" />
</cf:entity>
<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" />
<!--persistenceNullable is false, because the column for the foreign key must not be nullable.-->
<cf:property name="Customer" typeName="{0}.Customer" persistenceNullable="false" />
</cf:entity>
這裏是我的代碼:
Customer customer = new Customer();
customer.Save();
Order order = new Order();
order.Customer = customer;
order.Save();
customer.Delete();
的最後一條語句提供了以下錯誤: 不能將NULL值插入列 'Order_Customer_Id',表' CodeFluentTest.dbo.Order「;列不允許有空值。更新失敗。
這是因爲Customer_Delete存儲過程包含以下更新語句: UPDATE [訂購] SET [訂購] [Order_Customer_Id] = NULL WHERE([訂購] [Order_Customer_Id] = @Customer_Id。)
當然,這是行不通的,因爲Order_Customer_Id列是不可空的。 如何指示CodeFluent將值0而不是NULL置於Order_Customer_Id列中?