microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
279 stars 50 forks source link

Utilities.ToExpandoObject() changes DateTime values of Entity #404

Closed Demonofpower closed 9 months ago

Demonofpower commented 11 months ago

I get a Entity from the database and want to change some specific values of it.

image

When I now change a value (I don´t even have to change a value it is enough to just call ServiceClient.Update(Entity)) something strange occurs. image

My DateTime columns automatically get set 2 hours to the past. Eg. 12.12.2012 12:00 -> 12.12.2012 10:00 or even worse without time 12.12.2012 -> 11.12.2012 (I think because internally the time is 00:00)

I tried to find the cause of the problem and I was able to pin it down to the internal Utilities.ToExpandoObject() method. When the entity is converted to the ExpandoObject the DateTime variables get changed.

image image

Inside entity.Attributes: image

Inside rootExpando: image

Is this a bug in the internal implementation or did I do somehing wrong? Thank you very much

Demonofpower commented 11 months ago

I pinned down the problem even more and got to the point that the problematic conversion is HERE. It converts the Entity DateTime entry which has a "Unspecified" Kind by default (after getting it from database with a QueryExpression) to UTC which sets the time 2 hours to the past.

Is this the intended behaviour? If so what should I do. Do I have to change the Kind of every Entity each time I get it from the database manually even if I dont work with that columns?

MattB-msft commented 9 months ago

This has been a sore spot for us for a while... the answer is "It depends" . the API should be returning the base object for the date in UTC + offset. However, if you have set up a localization profile for your user, that is not aways what the API does.

This gets us in this client because we are doing Conversions off protocol to JSON and back for transit, so there is a 'best guess' going on as to what your (the clients) intentions actually are.

That said, if your using the current client versions, you should not be hitting this code path at all at this point. If you update to current, it maintains the original object and sends information to the OrgAPI as an DateTime natively.