开发者

Deleted object would be re-saved by cascade (remove deleted object from associations) in nhibernate

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:

开发者_StackOverflow社区 Repository().DbContext.CommitTransaction();
 Repository().DbContext.CommitChanges();

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜