dotnet / dotnet/efcore

Consider removing the partial trimming annotations introduced in EF Core 7.0

Open
#29,763 1 comment 2 reactions 0 assignees View on GitHub
area-aot area-model-building breaking-change needs-design
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

For EF Core 7.0, we introduced some trimming annotations to make basic scenarios work with aggressive trimming, the new default for console application (#29092). The main goal there was to prevent properties on entity CLR types from being trimmed, since EF accesses them at runtime via reflection and the linker cannot see that. For example, the T in `DbSet` was annotated to preserve all constructors/properties; but entity types without an explicit DbSet property (e.g. discovered via navigations) would still fail, and require explicit user intervention.

We are now exploring a full AOT approach to EF, where materializers are generated as C# code into the user's project. In that world, the above partial annotations are no longer needed, since the linker can see EF's access in plain (generated) C# code. We should consider removing these annotations.

This would mean that EF's trimming story is coupled to its AOT story (EF's AOT, not NativeAOT), i.e. we don't fully support trimming without AOT; or more precisely, if the user does trimming without AOT, it's their responsibility to annotate their own types as appropriate. I think this makes sense, since we can't fully solve this problem anyway (e.g. entity types discovered via navigations).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.