Refactor BytesToDateTimeConverter, so it works out-of-the-box with compiled models. #1847
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our previous
BytesToDateTimeConverter
implementation used methods calls in its convert to/from expressions that used a variable that was supplied to the convert expression. That is not supported by EF Core'sLinqToCSharpSyntaxTranslator.VisitInvocation()
implementation (would be trivial to implement though), which assumes that anInvocationExpression
always contains a lambda - which is not the case.We also accessed a
private static
field, which cannot be referenced from outside the class. Since the compiled model code generator does not create an instance of the value converter in question by default, but instead creates a general value converter that just uses the same expressions that we define in ours, no private fields could be accessed.The docs state:
While this seems to be just a suggestion, it seems to be a requirement for value converters in compiled models.
Fixes #1846