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.