EF 4.3 Beta 1 关于可选关系级联删除留下孤儿
这很奇怪吗?
删除一对多关系时,如果该关系是可选的,并且您删除了父对象,则其余对象将保持孤立状态,并且不会级联删除。
var album = new Album
{
Name = "Test Album",
Description = "Test Album Description",
Images = new Collection<Image>
{
new Image {
Name = "Image 1",
Description = "Image 1 Description"
},
new Image {
Name = "Image 2",
Description = "Image 2Description"
},
}
};
albumRepository.Add(album);
albumRepository.UnitOfWork.Commit();
在图像实体下,我将 AlbumId 设置为 Nullable,因为某些图像可能会被孤立。
然后我打电话。
albumRepository.Delete(toRemove);
albumRepository.UnitOfWork.Commit();
相册将被删除,但曾经相关的图像将被孤立,并且它们的 AlbumId 将从行中删除。
Is this odd?
When deleting relationships of one to many, if a the relationship is optional and you delete the parent object the rest will remain orphan and it does not cascade delete.
var album = new Album
{
Name = "Test Album",
Description = "Test Album Description",
Images = new Collection<Image>
{
new Image {
Name = "Image 1",
Description = "Image 1 Description"
},
new Image {
Name = "Image 2",
Description = "Image 2Description"
},
}
};
albumRepository.Add(album);
albumRepository.UnitOfWork.Commit();
Under the Image Entity I got the AlbumId as Nullable since some images can be orphaned.
And then I call.
albumRepository.Delete(toRemove);
albumRepository.UnitOfWork.Commit();
The Album gets deleted but the images that where once related are Orphaned and their AlbumId is removed from the row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这做到了。
This did it.