[6.0.x] Add [DynamicDependency] on DateOnly/TimeOnly for trimming #27910
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.
Description
Due to EF Core using wrappers to look up methods via reflection (GetRequiredRuntimeMethod), the linker cannot see the dependency on those methods, and trimmed applications fail.
Customer impact
It isn't possible to use EF Core's SQLite provider in a trimmed application.
How found
Customer report on 6.0
Regression
Yes, from 5.0. Although EF Core 5.0 was never officially trimming-compatible, at least basic scenarios were possible.
Testing
Coverage will be added in 7.0, where trimming will be a focus. The fix was verified manually.
Note that EF Core 6.0 still won't be fully trimming-compatible, but this unlocks at least the basic SQLite scenarios which customers were asking for.
Risk
Very low - the fix only adds an attribute which is meaningful only to the linker.
Details
This uses the [DynamicDependency] attribute to make sure System.DateOnly and TimeOnly aren't trimmed when using EF Core.
Fixes #27311
Similar to #27098