删除的对象将通过 nhibernate 中的级联(从关联中删除删除的对象)重新保存

发布于 2024-11-07 13:06:04 字数 632 浏览 7 评论 0原文

当我尝试从表中删除记录时,我不断收到此错误。除了删除之外,插入和更新工作正常。

这是我的设置:

Mappings:

 HasMany(x => x.Items).AsList().AsBag().LazyLoad().Cascade.AllDeleteOrphan();   

GetMethod:

  IRepositoryWithTypedId<BOD.Entities.Item, Guid> Rep = RepositoryFinder.For<BOD.Entities.Item, Guid>();
         BOD.Entities.Item tag = Rep.Get(new Guid("0A495241-082F-4314-8B79-000A524FC666"));

         Rep.Delete(tag); 

我也尝试过使用:

 Repository().DbContext.CommitTransaction();
 Repository().DbContext.CommitChanges();

这两个仍然会导致错误。有人有什么建议吗?

I keep getting this error when trying to delete a record from my table. Insert and Update work fine apart from delete.

Here is my set up:

Mappings:

 HasMany(x => x.Items).AsList().AsBag().LazyLoad().Cascade.AllDeleteOrphan();   

GetMethod:

  IRepositoryWithTypedId<BOD.Entities.Item, Guid> Rep = RepositoryFinder.For<BOD.Entities.Item, Guid>();
         BOD.Entities.Item tag = Rep.Get(new Guid("0A495241-082F-4314-8B79-000A524FC666"));

         Rep.Delete(tag); 

I have also tried using:

 Repository().DbContext.CommitTransaction();
 Repository().DbContext.CommitChanges();

These two still cause errors. Does anyone have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黄昏下泛黄的笔记 2024-11-14 13:06:04

这是因为 tag 包含在某个集合中,您应该将其从该集合中删除才能真正删除它。否则,当您持久化收集实体时,标签将再次保存。

this is because tag is contained in some collection, you should remove it from that collection to actually delete it. Otherwise when you persist the collecting entity, the tag will be saved again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文