RavenDB IDocumentStoreListener BeforeStore return false entity still saved

StackOverflow https://stackoverflow.com/questions/20764813

  •  21-09-2022
  •  | 
  •  

質問

According to RavenDB document, when BeforeStore() returns false, the entity instance should not updated.

Whatever the entity instance was modified and requires us re-serialize it. Returning true would force re-serialization of the entity, returning false would mean that any changes to the entityInstance would be ignored in the current SaveChanges call.

I have tested return both true and false, no difference. Return false won't stop saving the entity to database.

Here is my listener:

public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original)
{
    if (entityInstance is Person)
    {
        var person = (Person)entityInstance;
        person.Firstname = "Tom"; // used be John
        return false;
    }
}

It turns out the person's first name is changed to "Tom" even it returns false. Do I miss anything?

役に立ちましたか?

解決

Please re-read the documentation. The return value just says whether you have changed the document in your IDocumentStoreListener.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top