@@ -135,14 +135,23 @@ private List<GenerateDtoClassInfo> GenerateDtoClasses(
135135 var actualNamespace = GetActualDtoNamespace ( ) ;
136136
137137 // When NestedDtoUseHashNamespace option is enabled, child DTOs are placed in
138- // a hash-named sub-namespace (e.g., LinqraftGenerated_{Hash}.ClassName)
138+ // a hash-named sub-namespace (e.g., LinqraftGenerated_{Hash}) WITHOUT parent class nesting
139139 // However, DTOs with explicit names from nested SelectExpr should NOT use hash namespace
140+ // and should maintain their parent class structure
141+ List < string > finalParentClasses = currentParentClasses ;
142+ List < string > finalParentAccessibilities = currentParentAccessibilities ;
143+
140144 if ( ! isExplicitDto && Configuration ? . NestedDtoUseHashNamespace == true )
141145 {
142146 var hash = structure . GetUniqueId ( ) ;
143147 actualNamespace = string . IsNullOrEmpty ( actualNamespace )
144148 ? $ "LinqraftGenerated_{ hash } "
145149 : $ "{ actualNamespace } .LinqraftGenerated_{ hash } ";
150+
151+ // Implicit DTOs in hash namespace should NOT be nested inside parent classes
152+ // They are managed by the hash, so they don't need to exist within a class
153+ finalParentClasses = [ ] ;
154+ finalParentAccessibilities = [ ] ;
146155 }
147156
148157 var dtoClassInfo = new GenerateDtoClassInfo
@@ -152,8 +161,8 @@ private List<GenerateDtoClassInfo> GenerateDtoClasses(
152161 ClassName = className ,
153162 Structure = structure ,
154163 NestedClasses = [ .. result ] ,
155- ParentClasses = currentParentClasses ,
156- ParentAccessibilities = currentParentAccessibilities ,
164+ ParentClasses = finalParentClasses ,
165+ ParentAccessibilities = finalParentAccessibilities ,
157166 ExistingProperties = existingProperties ,
158167 IsExplicitRootDto = isExplicitDto , // Mark explicit DTOs (main or from nested SelectExpr) to avoid adding the attribute
159168 } ;
@@ -258,7 +267,8 @@ protected override string GetClassName(DtoStructure structure)
258267
259268 /// <summary>
260269 /// Gets the full name for a nested DTO class using the structure.
261- /// When NestedDtoUseHashNamespace is enabled, includes the LinqraftGenerated_{hash} namespace.
270+ /// When NestedDtoUseHashNamespace is enabled, includes the LinqraftGenerated_{hash} namespace
271+ /// WITHOUT parent class nesting (implicit DTOs are managed by hash, not class hierarchy).
262272 /// </summary>
263273 protected override string GetNestedDtoFullNameFromStructure ( DtoStructure nestedStructure )
264274 {
@@ -269,22 +279,20 @@ protected override string GetNestedDtoFullNameFromStructure(DtoStructure nestedS
269279 var actualNamespace = GetActualDtoNamespace ( ) ;
270280
271281 // When NestedDtoUseHashNamespace option is enabled, include LinqraftGenerated_{hash} in namespace
282+ // Implicit DTOs should NOT be nested inside parent classes - they are placed directly
283+ // in the LinqraftGenerated_{hash} namespace
272284 if ( Configuration ? . NestedDtoUseHashNamespace == true )
273285 {
274286 var hash = nestedStructure . GetUniqueId ( ) ;
275287 var generatedNamespace = string . IsNullOrEmpty ( actualNamespace )
276288 ? $ "LinqraftGenerated_{ hash } "
277289 : $ "{ actualNamespace } .LinqraftGenerated_{ hash } ";
278290
279- // Handle parent classes
280- if ( ParentClasses . Count > 0 )
281- {
282- return $ "global::{ generatedNamespace } .{ string . Join ( "." , ParentClasses ) } .{ className } ";
283- }
291+ // Implicit DTOs in hash namespace should NOT include parent classes
284292 return $ "global::{ generatedNamespace } .{ className } ";
285293 }
286294
287- // Default behavior: use GetNestedDtoFullName
295+ // Default behavior: use GetNestedDtoFullName (includes parent classes)
288296 return GetNestedDtoFullName ( className ) ;
289297 }
290298
0 commit comments