我有一個[Product] -1 - * - [Component]。所以當我刪除一個產品時,我想讓EF刪除它的所有組件。在設計師,我選擇的關係,併爲END1至級聯,其多樣性是0..1的OnDelete財產 - 這會產生類似:級聯刪除一對多關係
ALTER TABLE [dbo].[Components]
ADD CONSTRAINT [FK_ProductComponent]
FOREIGN KEY ([Product_Id])
REFERENCES [dbo].[Products]
([Id])
ON DELETE CASCADE ON UPDATE NO ACTION;
這對我來說,是指當一個組件被刪除,刪除應級聯,相關產品也應自動刪除。
這是從我想要的倒退。所以,我編輯的END2串級屬性(END1被重置爲無),但試圖保存模型,我得到的時候:
Error 28 Running transformation: End 'Text' on relationship
'EF.ProductComponent' cannot have operation specified since its multiplicity
is '*'. Operations cannot be specified on ends with multiplicity '*'. C:\Users
\me\Documents\Visual Studio 2010\Projects\X\Website\Models\EF.edmx
清楚,我不明白這一點。有可能做我想做的事,不是嗎?怎麼樣?
在上面你向後理解它。通過對外鍵約束應用「on delete」,你說......如果父母被刪除,也刪除我。 – RThomas 2011-05-28 03:49:59