Reputation: 136
I have a Entity mapped document stored in a RavenDb and one of the property which is stored as "string" should be "DateTime". In my C# code, i have changed the entity property to "DateTime" but while retrieving the same from RavenDb throws
Exception "Could not read value for property: {NameOfProperty}" due to conflict in dataType. How to resolve same?
Using version 3.0 of RavenDb
{ "Accountexpires": "11/31/9999 11:59:59 PM", "Cn": "XYZ", "Countrycode": "0", "Displayname": null, "DistinguishedName": "CN=XYZ,OU=Domain Controllers,DC=XYZ,DC=XYZ" }
Basically in this "Accountexpires" was a string in entity now it is "DateTime" so while fetching it gives error as mentioned previously.
Upvotes: 0
Views: 308
Reputation: 387
The value in the string property is not valid for a DateTime value so simply changing the type won't work.
Consider adding another DateTime field and processing all documents in the collection: Load the document, parse the Accountexpires field to a DateTime value and save it to the new field. Then change your code to use the added DateTime field. You can then delete the old string field if you don't need it anymore.
Otherwise, you need to process all the documents in the collection and change the string to valid RavenDB DateTime format (9999-11-31T23:59:59.0000000), then change the datatype and it should work.
The latter approach as a disadvantage that the switch is not instantaneous, there will be a period of time when the data will be inconsistent. The former process allows you to prepare the data and switch the code immediately.
Upvotes: 1