Skip to content

Fix BuildMap() generating orphaned [Map] attribute when mapped table has no display field#89

Merged
xxred merged 3 commits into
masterfrom
copilot/xcodetool-map-feature-fix
Jul 19, 2026
Merged

Fix BuildMap() generating orphaned [Map] attribute when mapped table has no display field#89
xxred merged 3 commits into
masterfrom
copilot/xcodetool-map-feature-fix

Conversation

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

When a column uses Map="ProductRelease@Id" (table+key only, no display field) and the mapped table has neither a Master column nor a Name column, BuildMap() wrote a [Map(...)] attribute with no following property declaration — invalid C#:

/// <summary>发布版本</summary>
[Map(nameof(ReleaseId), typeof(ProductRelease), "Id")]

#endregion

Changes

  • XCode/Code/EntityBuilder.cs

    • Added && (mapName != null || useToString) guard on the string extension property block so [Map(...)] is never emitted without a corresponding property
    • Fixed IndexOutOfRangeException in the mapTable == null branch: ss[2] access is now guarded by else if (ss.Length > 2)
    • Extracted repeated ss.Length > 2 && ss[2] == "$" into a useToString local variable to eliminate duplication
  • XUnitTest.XCode/Code/EntityBuilderTests.cs

    • Added BuildMap_NoDisplayField_NoOrphanedMapAttribute test covering the exact scenario from the issue — verifies no orphaned [Map] attribute is emitted and the object-reference property (Extends.Get pattern) is still correctly generated

Copilot AI linked an issue Jul 17, 2026 that may be closed by this pull request
Copilot AI added 2 commits July 17, 2026 04:57
…eld available

When Map attribute specifies only "Table@Id" (no display field) and the mapped
table has no Master column or "Name" column, the BuildMap() method was writing
a [Map(...)] attribute with no following property declaration, resulting in
invalid C# code.

Fix 1: In the `else` branch (mapTable is null), guard ss[2] access with
  `else if (ss.Length > 2)` to avoid IndexOutOfRangeException.

Fix 2: Add `(mapName != null || (ss.Length > 2 && ss[2] == "$"))` to the
  condition for generating the string extension property, so [Map(...)] and
  the property are only generated when a display field is available.

Closes #88
- Extract `ss.Length > 2 && ss[2] == "$"` into `useToString` variable to eliminate duplication
- Improve test assertion to verify the exact Extends.Get property declaration is generated
Copilot AI changed the title [WIP] Fix xcodetool generation of entities with Map feature Fix BuildMap() generating orphaned [Map] attribute when mapped table has no display field Jul 17, 2026
Copilot finished work on behalf of xxred July 17, 2026 05:02
Copilot AI requested a review from xxred July 17, 2026 05:02
@xxred
xxred marked this pull request as ready for review July 19, 2026 17:20
@xxred
xxred merged commit 2b009f9 into master Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xcodetool生成带Map特性拓展字段问题

2 participants