Attachments: Deleting Attachments

Delete from session.Advanced.Attachments is used to remove an attachment from a document.

Syntax

void Delete(string documentId, string name);
void Delete(object entity, string name);

Example

using (var session = store.OpenSession())
{
    Album album = session.Load<Album>("albums/1");
    session.Advanced.Attachments.Delete(album, "001.jpg");
    session.Advanced.Attachments.Delete("albums/1", "002.jpg");

    session.SaveChanges();
}
using (var asyncSession = store.OpenAsyncSession())
{
    Album album = await asyncSession.LoadAsync<Album>("albums/1");
    asyncSession.Advanced.Attachments.Delete(album, "001.jpg");
    asyncSession.Advanced.Attachments.Delete("albums/1", "002.jpg");

    await asyncSession.SaveChangesAsync();
}