Pergunta

Im having trouble with what should be a simple task in RavenDB. In know how to delete a document in Raven in this manner

Session.Delete("Artist/1")

Now, Im not looking to delete the entire document. I only want to delete one of the list-objects in "Album".

Id: Artist/1
  "Artist": 
  "Image": "imgOfArtist",

  "Album": [
    {
      "Id": "1",
      "Title": ""
      "AlbumCover": "linkToCover"
    },
    {
      "Id": "2",
      "Title": ""
      "AlbumCover": "linkToCover"
    }
  ],

How can this be done? It seem to me that a good start is to load the document like this:

var theDoc = Session.Load<AllArtists>("Artist/1");

Then maybe i Should do something like this:

var Todelete = theDoc.Albums.Where(o => o.Id == 1);

Session.Delete(Todelete);

This gives me the following error: System.Linq.Enumerable+WhereListIterator`1[XXXXXXXXX.Albums] is not associated with the session, cannot delete unknown entity instance

Foi útil?

Solução

You need to just remove the document value.

var artist = Session.Load<AllArtists>("artists/1");
artists.Albums.RemoveAt(3);
Session.SaveChages();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top