-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Currently, the NullConditionalRewriteSupport setting on the [Projectable] attribute defaults to NullConditionalRewriteSupport.None if not explicitly specified. While this provides granular control, I've found that in many projects, the decision regarding null conditional rewrites is a system-wide consideration rather than being property-specific. This leads to repetitive boilerplate code, as I frequently have to explicitly set NullConditionalRewriteSupport.X on numerous [Projectable] attributes throughout the codebase, even when the desired behavior is consistent across the application. This becomes quite tiresome and can clutter the code.
Proposal
I propose enhancing the ProjectableOptionsBuilder to include an option for setting the default NullConditionalRewriteSupport. The UseProjectables() method in EntityFrameworkCore.Projectables.Extensions.DbContextOptionsExtensions.cs already accepts an Action<ProjectableOptionsBuilder>? configure argument. My suggested solution is to extend the ProjectableOptionsBuilder (defined in EntityFrameworkCore.Projectables.Infrastructure.ProjectableOptionsBuilder.cs) to allow developers to configure this global default directly when enabling Projectables.
This would allow for a clean and centralized configuration, for example:
dbContextOptions.UseProjectables(options =>
{
options.SetDefaultNullConditionalRewriteSupport(NullConditionalRewriteSupport.X);
});This approach aligns well with how other Entity Framework Core options are typically configured within the DbContextOptions setup, providing a consistent and intuitive way to manage projectable-specific settings. When a [Projectable] attribute does not explicitly define NullConditionalRewriteSupport, it would then fall back to the value set via SetDefaultNullConditionalRewriteSupport.
Alternatives
I have considered the current approach of manually setting NullConditionalRewriteSupport on each [Projectable] attribute. However, as described, this leads to significant repetition and maintainability overhead in projects where a consistent null conditional rewrite strategy is desired across many projected properties.
Another alternative would be to introduce a static global default setting, for instance, EntityFrameworkCore.Projectables.NullConditionalRewriteSupportDefault. This static property could be initialized with NullConditionalRewriteSupport.None and then overridden early in the application's lifecycle, such as in Program.cs. While functional, I believe the ProjectableOptionsBuilder approach offers better integration with the existing DbContextOptions configuration flow and provides a more encapsulated way to manage projectable-specific options.
Additional context
This feature would greatly improve developer experience and reduce code verbosity for projects utilizing EntityFrameworkCore.Projectables where a consistent null conditional rewrite strategy is preferred. It would allow for a cleaner and more concise declaration of projectable properties by removing the need to repeatedly specify the same NullConditionalRewriteSupport value.