0

Background: In my application (with Entity Framework 6 and .net 4.5), several tables contain DateTime fields and I need to convert the DateTimekind from unspecified to UTC in the received entities (as EF materializes the DateTimeKind as unspecified). For this purpose I made a custom attribute and used reflection to convert the kind to UTC. The idea is adapted from here: https://stackoverflow.com/a/19301623/1559311.

Since it happens during reflection, the process is done for each row returned and this slows down the query return time a bit.

Question: How can some kind of caching mechanism can be implemented to avoid reflection on every retrieved row? So that retrieved entities are cached and the conversion is applied from unspecified to UTC and then the result is given to the place from where the query is executed.

Community
  • 1
  • 1
Flair
  • 2,899
  • 5
  • 21
  • 22
  • This statement sounds contradictory `DateTime fields and I need to convert the DateTime.kind from unspecified to UTC` if you know that they are defined as `DateTime` how then can you state `unspecified` am I missing and or not understanding something here..? can you show an example of the code perhaps you're logic may have flaws in it initially – MethodMan Apr 15 '14 at 16:29
  • @DJ KRAZE Entity Framework materializes DateTime type fields as unspecified kind ([FYI](http://blog.3d-logic.com/2012/04/08/entity-framework-and-datetime-of-unspecified-kind/)), and I want it the kind as UTC. But this is not the problem as I already have the solution for this. The only question is- how to use caching to avoid extra execution time during reflection. – Flair Apr 16 '14 at 07:46

0 Answers0