2

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Funky
  • 12,890
  • 35
  • 106
  • 161
  • 2
    FYI, get rid of the `AsList()` call in your mapping, unless you want it to be mapped as an nhibernate list (ie with an index column). The `AsBag()` call is overriding it, but you don't want to specify two different collection mapping specifications. – Vadim May 16 '11 at 16:39
  • 2
    it wasn't supposed to fix your problem, just something for you to be aware of. – Vadim May 17 '11 at 14:21

1 Answers1

3

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.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115