Skip to content

Commit 44a0e2d

Browse files
committed
Fix File-column typing and suppress OData-shadowed nav props
- Bump Microsoft.CrmSdk.XrmTooling.CoreAssembly to 9.1.1.65 so the SOAP deserializer returns FileAttributeMetadata instead of silently dropping it - Type File columns as string | null (matching the Web API GUID wire value) - Add isShadowedByScalar filter: nav props whose name is claimed by a non-lookup scalar (File, Uniqueidentifier, etc.) are now excluded from ManyToOne read/write interfaces and @odata.bind entries, matching the OData CSDL which cannot expose both a Property and NavigationProperty under the same name
1 parent 24dc9b8 commit 44a0e2d

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
### Fixed
1919
- Updated `xrm.d.ts` from the original XRM library
2020
- Fixed ManyToMany relationship navigation property names being swapped when the current entity is the second entity in the relationship
21+
- File-type columns now appear in generated typings as `string | null` (previously silently dropped by the old SDK SOAP deserializer); requires `Microsoft.CrmSdk.XrmTooling.CoreAssembly` ≥ 9.1.1.65
22+
- Navigation properties that are shadowed by a same-named non-lookup scalar (e.g. File, Uniqueidentifier) are now suppressed from `ManyToOne` read/write interfaces and `@odata.bind` create/update interfaces, matching the OData CSDL wire surface
2123

2224
## [1.3.0] - 2026-04-15
2325
### Changed

src/CreateTypeScript/CreateWebEntities.fs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,24 @@ let getScalarType (attr: XrmAttribute) =
7171
| _ -> attr.varType
7272

7373
(** Variable functions *)
74+
75+
/// True when an attribute on the entity claims the same OData property name as the given
76+
/// navigation property name. Lookup-style attributes (specialType = EntityReference) are
77+
/// renamed to `_<name>_value` in the OData CSDL so they don't shadow; everything else
78+
/// (Uniqueidentifier, File, Image, plain scalars) keeps its natural name and forces
79+
/// Dataverse to drop the navigation property from the wire.
80+
let private isShadowedByScalar (attrMap: Map<string, XrmAttribute>) navPropName =
81+
Map.tryFind navPropName attrMap
82+
|> Option.exists (fun a -> a.specialType <> SpecialType.EntityReference)
83+
7484
let getBindVars (nameMap: Map<string, EntityInfo>) (filter: XrmAttribute -> bool) (entity: XrmEntity) =
7585
let attrMap = entity.attributes |> List.map (fun a -> a.logicalName, a) |> Map.ofList
7686

7787
entity.manyToOneRelationships
7888
|> List.filter (fun rel ->
7989
not (isNull rel.ReferencingEntityNavigationPropertyName)
80-
&& Map.tryFind rel.ReferencingAttribute attrMap |> Option.exists filter)
90+
&& Map.tryFind rel.ReferencingAttribute attrMap |> Option.exists filter
91+
&& not (isShadowedByScalar attrMap rel.ReferencingEntityNavigationPropertyName))
8192
|> List.map (fun rel ->
8293
let eInfo = Map.find rel.ReferencedEntity nameMap
8394

@@ -110,9 +121,13 @@ let getLookupValueVars (attrs: XrmAttribute list) =
110121
let private toInterfaceName forWrite schemaName =
111122
if forWrite then $"{schemaName}.{CREATE_INTERFACE_NAME}" else schemaName
112123

113-
let getManyToOneVars nameMap (schemaNames: Set<string>) forWrite (rels: OneToManyRelationshipMetadata list) =
114-
rels
115-
|> List.filter (fun rel -> not (isNull rel.ReferencingEntityNavigationPropertyName))
124+
let getManyToOneVars nameMap (schemaNames: Set<string>) forWrite (entity: XrmEntity) =
125+
let attrMap = entity.attributes |> List.map (fun a -> a.logicalName, a) |> Map.ofList
126+
127+
entity.manyToOneRelationships
128+
|> List.filter (fun rel ->
129+
not (isNull rel.ReferencingEntityNavigationPropertyName)
130+
&& not (isShadowedByScalar attrMap rel.ReferencingEntityNavigationPropertyName))
116131
|> List.map (fun rel ->
117132
let eInfo = Map.find rel.ReferencedEntity nameMap
118133

@@ -387,15 +402,15 @@ let getEntityInterfaceLines nameMap (schemaNames: Set<string>) (entity: XrmEntit
387402
let readInterfaces =
388403
[
389404
entityInterfaces.readRelationships
390-
{ entityInterfaces.readManyToOne with vars = getManyToOneVars nameMap schemaNames false entity.manyToOneRelationships }
405+
{ entityInterfaces.readManyToOne with vars = getManyToOneVars nameMap schemaNames false entity }
391406
{ entityInterfaces.readOneToMany with vars = getOneToManyVars nameMap schemaNames false entity.oneToManyRelationships }
392407
{ entityInterfaces.readManyToMany with vars = getManyToManyVars nameMap schemaNames false entity }
393408
]
394409

395410
let writeInterfaces =
396411
[
397412
entityInterfaces.writeRelationships
398-
{ entityInterfaces.writeManyToOne with vars = getManyToOneVars nameMap schemaNames true entity.manyToOneRelationships }
413+
{ entityInterfaces.writeManyToOne with vars = getManyToOneVars nameMap schemaNames true entity }
399414
{ entityInterfaces.writeOneToMany with vars = getOneToManyVars nameMap schemaNames true entity.oneToManyRelationships }
400415
{ entityInterfaces.writeManyToMany with vars = getManyToManyVars nameMap schemaNames true entity }
401416
]

src/Interpretation/InterpretEntityMetadata.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ let interpretNormalAttribute aType (options:OptionSet option) =
4141

4242
| XrmAttributeType.Uniqueidentifier -> TsType.String, SpecialType.Guid
4343

44+
| XrmAttributeType.File -> TsType.String, SpecialType.Default
45+
4446
| _ -> typeConv aType, SpecialType.Default
4547

4648
let interpretAttribute (nameMap: Map<string, EntityInfo>) labelMapping (a: AttributeMetadata) =

src/XrmTypeScript.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<None Include="EnvInfo.config" />
6363
</ItemGroup>
6464
<ItemGroup>
65-
<PackageReference Include="Microsoft.CrmSdk.XrmTooling.CoreAssembly" Version="9.1.0.51" />
65+
<PackageReference Include="Microsoft.CrmSdk.XrmTooling.CoreAssembly" Version="9.1.1.65" />
6666
</ItemGroup>
6767
<ItemGroup>
6868
<Reference Include="mscorlib" />

0 commit comments

Comments
 (0)