You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

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();
}