public void RemoveTags(string photoId, Tag[] tags) { var context = new PhotoAlbumDataContext(); foreach (var tag in tags) { var photoTag = new PhotoTagRow(photoId, tag.Name); context.AttachTo(PhotoAlbumDataContext.PhotoTagTable, photoTag, "*"); context.DeleteObject(photoTag); } try { // continue trying to delete, even if not found context.SaveChanges(SaveChangesOptions.ContinueOnError); } catch (DataServiceRequestException ex) { foreach (var resp in ex.Response) { // to be more robust, we will ignore 404 errors when // the entity might have already been deleted (due to an // incomplete operation earliet). if (resp.StatusCode != (int)HttpStatusCode.NotFound && resp.StatusCode != (int)HttpStatusCode.OK) { throw; } } } }
public void RemoveTags(string photoId, Tag[] tags) { var context = new PhotoAlbumDataContext(); foreach (var tag in tags) { var photoTag = new PhotoTagRow(photoId, tag.Name); context.AttachTo(PhotoAlbumDataContext.PhotoTagTable, photoTag, "*"); context.DeleteObject(photoTag); } try { // continue trying to delete, even if not found context.SaveChanges(SaveChangesOptions.ContinueOnError); } catch (DataServiceRequestException ex) { foreach (var resp in ex.Response) { // to be more robust, we will ignore 404 errors when // the entity might have already been deleted (due to an // incomplete operation earliet). if (resp.StatusCode != (int)HttpStatusCode.NotFound && resp.StatusCode != (int)HttpStatusCode.OK) { throw; } } } }