Home > database >  How to verify whether the update is success or not in the RavenDB in .NET6?
How to verify whether the update is success or not in the RavenDB in .NET6?

Time:05-24

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?

CodePudding user response:

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

CodePudding user response:

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.
  • Related