In Projectables 6.x, a settable [Projectable] property is populated when an untracked query materializes the whole entity. In Projectables 3.x, the property remained null unless the query used it in an expression.
For example:
var posts = await db.Posts
.AsNoTracking()
.ToListAsync();
With a settable projectable:
[Projectable(UseMemberBody = nameof(DisplayTitleExpression))]
[NotMapped]
public string? DisplayTitle { get; set; }
private string? DisplayTitleExpression =>
Blog == null ? null : Blog.Name + ": " + Title;
The query computes DisplayTitle and assigns it during materialization, even when the caller only needs the entity’s other properties.
This can add significant SQL and materialization work to whole-entity queries, especially when projectables contain correlated subqueries or other expensive expressions. Consumers may never read the resulting values.
Making the property read-only is not a suitable workaround for every application. HotChocolate's [UseProjection] needs setters to populate projectable properties. #129 Describes the HotChocolate requirements.
Expected behavior
Keep settable projectables available for query expressions and HotChocolate projections, while allowing consumers to opt out of populating them when a query materializes a whole entity.
A configuration option such as UseProjectables(o => o.PopulateSettableProperties(false)) could provide that control.
#84 #86 Introduced the automatic hydration behavior
In Projectables 6.x, a settable
[Projectable]property is populated when an untracked query materializes the whole entity. In Projectables 3.x, the property remained null unless the query used it in an expression.For example:
With a settable projectable:
The query computes
DisplayTitleand assigns it during materialization, even when the caller only needs the entity’s other properties.This can add significant SQL and materialization work to whole-entity queries, especially when projectables contain correlated subqueries or other expensive expressions. Consumers may never read the resulting values.
Making the property read-only is not a suitable workaround for every application. HotChocolate's
[UseProjection]needs setters to populate projectable properties. #129 Describes the HotChocolate requirements.Expected behavior
Keep settable projectables available for query expressions and HotChocolate projections, while allowing consumers to opt out of populating them when a query materializes a whole entity.
A configuration option such as
UseProjectables(o => o.PopulateSettableProperties(false))could provide that control.#84 #86 Introduced the automatic hydration behavior