How to temporarily exclude property from getting saved to RavenDb?

Viewed 162

I need to store some data from user input to RavenDb. But while the user is typing some property might have changed which I don't want to get overwritten. So I want to temporarily exclude this property from getting saved. Is that possible? I know the solution with "JsonIgnore", but then the property would be ignored permanently.

1 Answers

I think that a better approach would be to reverse this question. Instead of trying to save the whole object, and ignore changes to a particular property, why not just set the properties that you want to set?

Here are the relevant docs:

https://ravendb.net/docs/article-page/4.2/csharp/client-api/operations/patching/single-document#change-values-of-two-fields

And this is how you set just two properties, and leave the rest as is:

session.Advanced.Patch<Employee, string>("employees/1", x => x.FirstName, "Robert");
session.Advanced.Patch<Employee, string>("employees/1", x => x.LastName, "Carter");

session.SaveChanges();
Related