Repository navigation
Fix/selectfacet derived and global namespace - #452
Merged
Merged
Conversation
SelectFacet<TSource, TTarget> hard-cast the facet's declared projection to
Expression<Func<TSource, TTarget>>, so querying a subtype of the declared
source threw InvalidCastException, e.g. an EF table-per-hierarchy
db.Set<Admin>().ToFacetsAsync<Admin, UserDto>(). Every EF *FacetAsync
overload with explicit type arguments goes through it. It now reuses the
non-generic overload's path: the cached declared projection, with the
parameter adapted by a cast when TSource derives from the declared source.
Multi-source facets looked up ProjectionFrom{TSource.Name}, which misses for
a subtype in both overloads; the lookup now uses the declared source the
element type derives from.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A type declared without a namespace has the fully qualified name global::Name, which has no dot, so GetSimpleTypeName returned it whole. Generated member names then read ProjectionFromglobal::User (CS0687), and any [Facet] of such a type failed to compile - the first thing a top-level-statement or minimal API app runs into. The global:: prefix is now stripped first; namespaced names are unchanged. Adds driver-based tests compiling global-namespace facets (single-source, multi-source, facet in a namespace) and GenerateDtos, plus CHANGELOG entries for this and the SelectFacet derived-type fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 2, 2026
This was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
1. SelectFacet / EF
*FacetAsyncwith a derived source type (src/Facet.Extensions/FacetExtensions.cs)SelectFacet<TSource, TTarget> hard-cast the declared projection to
Expression<Func<TSource, TTarget>>. WhenTSourcederives from the facet's source, for example an EF table-per-hierarchy subtype likedb.Set<Admin>().ToFacetsAsync<Admin, UserDto>()with[Facet(typeof(User))], that cast threwInvalidCastException. Every EF*FacetAsyncoverload with explicit type arguments goes through this method.It now reuses the non-generic overload's path: the cached declared projection, with the parameter adapted by a Convert when TSource is a subtype. EF translates that cast for TPH; the Sqlite tests run real SQL. For a declared source, the projection is used unchanged.
Bonus: this overload used to reflect on every query, and now uses the existing cache.
Multi-source facets looked up
ProjectionFrom{TSource.Name}, which doesn't exist for a subtype. The lookup now uses the declared source the element type derives from. This also fixes the non-genericSelectFacet<TTarget>().The error message, when there really is no projection, now names the source type.
2.
[Facet]of a type in the global namespace (src/Facet/Generators/FacetGenerators/CodeGenerationHelpers.cs)A type declared without a namespace has the fully qualified name
global::User, which has no dot.GetSimpleTypeNametherefore returned it whole, and the generated members readProjectionFromglobal::User(CS0687). Any facet of such a type failed to compile, and top-level-statement and minimal API apps hit this first. The global:: prefix is now stripped before splitting; names of namespaced types are unchanged.