Delete-Discussion and Delete-DiscussionReply Errors in V 1.7

  • 464 Views
  • Last Post 13 May 2016
Rich Bianco posted this 13 October 2015

If deleting a discussion-reply that has-a-like an error occurs, need to unlike first. It is possible that the same problem may be seen if a discussion has a favorite or other ancillary record attached.

If deleting a discussion that has-a-discussion-reply an error occurs, most likely because it would cause a phantom discussion reply. My test case the discussion-reply had-a-like so it is possible the cascade delete worked for the discussion-reply but the like prevented the discussion-reply from being deleted as indicated in first paragraph- sorry I did not have time to research further today.

I have forked a copy of the software (rbianco3) and will try fixing this and updating this as I find out more.

  • Liked by
  • Oktaokta
Order By: Standard | Newest | Votes
YodasMyDad posted this 14 October 2015

It should delete everything asit explicitly checks for votes and posts to delete

https://github.com/leen3o/mvcforum/blob/master/MVCForum.Services/PostService.cs#L224

Oktaokta posted this 04 November 2015

I am having the same problem. Deleting discussions works fine as long as there are no likes, no favorites, or no uploaded files recorded for said discussion. Here are the innerexceptions thrown in SaveChanges method of class MVCForumContext.cs.

Innerexception:
{"A relationship from the 'Post_Votes' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Post_Votes_Target' must also in the 'Deleted' state."}
[this post had likes]

Innerrexception:
{"The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.Favourite_dbo.Post_PostId\". The conflict occurred in database \"X_Community_LIVE\", table \"dbo.Favourite\", column 'PostId'.\r\nThe statement has been terminated."}
[this post was favorited]

Innerexception:
{"The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.UploadedFile_dbo.Post_Post_Id\". The conflict occurred in database \"X_Community_LIVE\", table \"dbo.UploadedFile\", column 'Post_Id'.\r\nThe statement has been terminated."}
[there was an uploaded file for this post]

Any update on this?

Oktaokta posted this 04 November 2015

I guess this could be a fix, added to PostService.cs, in method Delete, directly below the line: _membershipUserPointsService.Delete(PointsFor.Solution, post.Id);

            // remove likes
            var postLikes = post.Votes.ToList();
            foreach (var like in postLikes)
            {
                _voteService.Delete(like);
            }

            // remove favorites
            var postFavorites = post.Favourites.ToList();
            foreach (var favorite in postFavorites)
            {
                _favouriteService.Delete(favorite);
            }

            // remove uploaded files
            var postUploads = post.Files.ToList();
            foreach (var postUploadedFile in postUploads)
            {
                _uploadedFileService.Delete(postUploadedFile);
            }

Thoughts?

YodasMyDad posted this 05 November 2015

This is fixed in the v1.8 branch. Will be rolled out with v1.8

Frank Coyle posted this 13 May 2016

Just adding that this is still an issue in v1.8.

 

Close