3

Below is the update code to update the existing entity in the RavenDB. The below code sometimes works and sometimes does not work.

using var session = GetDocumentStore().OpenAsyncSession();
var stored = await session.LoadAsync<Bundle>(bundle.Id);
stored = Mapper.Map(bundle, stored);
await session.SaveChangesAsync();

There is neither any exceptions nor warning when above code block is executed when the update does not happen. Let me know if more stuffs are required from my end to support the question.

I need to verify whether the update is successful or not. Is there any approach to verify whether the update is success in RavenDB?

Bijay Yadav
  • 928
  • 1
  • 9
  • 22

2 Answers2

3

If there is no exception the batch command including your update has succeeded. In most cases the document "was't updated" is because another request modified it back. If you configure revision to your database/collection you can track the document modifications - https://ravendb.net/docs/article-page/4.2/csharp/server/extensions/revisions

  • The only thing which I found different is the 'Hash Code' of the object before and after the execution of 'AutoMapper'. So, when the 'Hash Code' is same before and after the map then the update works fine otherwise no update. Any thoughts? Thanks – Bijay Yadav May 24 '22 at 07:53
2

Based of THIS document, SaveChangesAsync is Void Type. So in my opinion there is two option:


1-Using a Try… Catch block in this case if any exception is thrown by the DB you can handle it.
2-if validating is that much important. You can fetch it by the ID and then validate.
Hussein Beygi
  • 391
  • 2
  • 7
  • 1
    1 - There is no exception being thrown, is there any explicit configurations to be done to force the CRUD operations to throw an exception when it does not work? 2 - This helps to validate whether the update is done or not. But, does not provide the root cause why the update did not happen. – Bijay Yadav May 24 '22 at 03:27
  • 1
    If there is no exception the request was successful. The exception will contain the information in a failure. – Igal Merhavia May 26 '22 at 08:34