OrleansContrib/Orleans.Providers.MongoDB

About default values

bboyle1234 opened this issue · 9 comments

A grain has its state object defined as shown below. EventNumber is a long.

image

The first time the grain is run, the field DiscoveredPosition.EventNumber is incremented to zero and the state is saved to mongodb.

This image, with an arrow pointer, shows that the data serialization has not specifically saved the value of DiscoveredPosition.EventNumber because it considers the value of 0 to be the default value.

image

The next time the grain is run, the state is incorrectly rehydrated with DiscoveredPosition.EventNumber equal to -1.

What is the fix for this?

I don't get it. The value after deserialization will be also 0, so where is the problem?

Because of the way I've setup the initializer at -1, and because the "0" is missing from the serialized representation, the value after deserialization is -1, NOT 0

The deserializer is leaving the field value untouched intead of adjusting it to 0

Just make a pull request for the current implementation ;)

Hi @SebastianStehle :) Will there be a nuget release soon? I'd love to get this into production.

Done, should be available soon. I can also add you to the project if you want. I am not using the provider myself.

Please add me to the project :) Thank you.