1

I have the following code that opens a session with RavenDB, gets the relevant IDs, uses those ideas to load the entities, change them, and finally save them.

List<EventDescriptor> events;

using (var session = raven.OpenSession())
{
    session.Store(aggregate);
    session.SaveChanges();

    events = (from descriptor in session.Query<EventDescriptor>() where descriptor.AggregateId == aggregate.Id select descriptor).ToList();
}

using (var session = raven.OpenSession())
{
    foreach (var @event in events)
    {
        var e = session.Load<EventDescriptor>("EventDescriptors/" + @event.Id.ToString());
        e.Saved = true;
    }

    session.SaveChanges();
}

The problem however is that the changes in the entities don't seem to be tracked, and I can't delete the entities either (gives me unknown entity error), even though the object is loaded. I already tried calling SaveChanges inside the loop, but that didn't help either. I looked at the Raven documentation but I don't see what I'm doing wrong here.

Fedor Finkenflugel
  • 335
  • 1
  • 4
  • 15

2 Answers2

2

Yes, we can't track changes on structs, because every time that you change them, you create a new copy

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
1

The problem was that EventDescriptor was a struct, and not a class. Changing this solved the problem. I assume it's because a struct is a valuetype and not a referencetype.

Fedor Finkenflugel
  • 335
  • 1
  • 4
  • 15