diff --git a/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel.Tests/Utilities/TraitToPropertyMapTests.cs b/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel.Tests/Utilities/TraitToPropertyMapTests.cs
index 595a2c1713..4d9e005faa 100644
--- a/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel.Tests/Utilities/TraitToPropertyMapTests.cs
+++ b/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel.Tests/Utilities/TraitToPropertyMapTests.cs
@@ -102,6 +102,33 @@ public async Task TestFetchPrimaryKey()
}
}
+ ///
+ /// Test fetching primary key of a resolved entity from an abstract manifest.
+ ///
+ [TestMethod]
+ public async Task TestFetchAbstractPrimaryKey()
+ {
+ var corpus = TestHelper.GetLocalCorpus(testsSubpath, nameof(TestFetchAbstractPrimaryKey));
+ var doc = await corpus.FetchObjectAsync("Account.cdm.json");
+
+ if (doc == null)
+ {
+ Assert.Fail($"Unable to load acccount.cdm.json. Please inspect error log for additional details.");
+ }
+
+ var entity = (CdmEntityDefinition)doc.Definitions[0];
+ var resolvedEntity = await entity.CreateResolvedEntityAsync("ResolvedAccount");
+ try
+ {
+ var pk = resolvedEntity.PrimaryKey;
+ Assert.IsNotNull(pk);
+ }
+ catch (Exception e)
+ {
+ Assert.Fail($"Exception occur while reading primary key for entity account. {e.Message}");
+ }
+ }
+
///
/// Test setting and getting of data format
///
diff --git a/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel/Utilities/TraitToPropertyMap.cs b/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel/Utilities/TraitToPropertyMap.cs
index 0590aaacf7..4bed42aabc 100644
--- a/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel/Utilities/TraitToPropertyMap.cs
+++ b/objectModel/CSharp/Microsoft.CommonDataModel.ObjectModel/Utilities/TraitToPropertyMap.cs
@@ -203,7 +203,7 @@ internal dynamic FetchPropertyValue(string propertyName, bool onlyFromProperty =
{
return attRef;
}
- return ((CdmTypeAttributeDefinition)attRef).FetchObjectDefinitionName();
+ return ((CdmObject)attRef).FetchObjectDefinitionName();
}
break;
case "defaultValue":
diff --git a/objectModel/TestData/Utilities/TraitToPropertyMap/TestFetchAbstractPrimaryKey/Input/Account.cdm.json b/objectModel/TestData/Utilities/TraitToPropertyMap/TestFetchAbstractPrimaryKey/Input/Account.cdm.json
new file mode 100644
index 0000000000..62503bceb6
--- /dev/null
+++ b/objectModel/TestData/Utilities/TraitToPropertyMap/TestFetchAbstractPrimaryKey/Input/Account.cdm.json
@@ -0,0 +1,20 @@
+{
+ "jsonSchemaSemanticVersion": "1.0.0",
+ "imports": [
+ {
+ "corpusPath": "cdm:/foundations.cdm.json"
+ }
+ ],
+ "definitions": [
+ {
+ "entityName": "Account",
+ "hasAttributes": [
+ {
+ "name": "accountId",
+ "purpose": "identifiedBy",
+ "dataType": "entityId"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file