Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top