@@ -1058,5 +1058,74 @@ public void When_There_Are_Multiple_LinkedEntities_With_The_Same_Entitiy_And_One
1058
1058
Assert . Equal ( "User2" , ( ( AliasedValue ) resultingEntity [ "systemuserwithalias.fullname" ] ) . Value ) ;
1059
1059
Assert . Equal ( "User1" , ( ( AliasedValue ) resultingEntity [ "systemuser2.fullname" ] ) . Value ) ;
1060
1060
}
1061
+
1062
+ [ Fact ]
1063
+ public void TestRetriveMultipleWithLinkEntityWithAlternateNullField ( )
1064
+ {
1065
+ // ARRANGE
1066
+
1067
+ List < Entity > initialEntities = new List < Entity > ( ) ;
1068
+
1069
+ Entity parentEntity = new Entity ( "parent" ) ;
1070
+ parentEntity [ "parentname" ] = "parent name" ;
1071
+ parentEntity . Id = Guid . NewGuid ( ) ;
1072
+ initialEntities . Add ( parentEntity ) ;
1073
+
1074
+ // create the first child which has the "myvalue" field set to "value"
1075
+ Entity childEntity1 = new Entity ( "child" ) ;
1076
+ childEntity1 [ "parent" ] = parentEntity . ToEntityReference ( ) ;
1077
+ childEntity1 [ "name" ] = "entity1" ;
1078
+ childEntity1 [ "myvalue" ] = "value" ;
1079
+ childEntity1 . Id = Guid . NewGuid ( ) ;
1080
+ initialEntities . Add ( childEntity1 ) ;
1081
+
1082
+ // create the second child which has the "myvalue" field set to null
1083
+ Entity childEntity2 = new Entity ( "child" ) ;
1084
+ childEntity2 [ "parent" ] = parentEntity . ToEntityReference ( ) ;
1085
+ childEntity2 [ "name" ] = "entity2" ;
1086
+ childEntity2 [ "myvalue" ] = null ;
1087
+ childEntity2 . Id = Guid . NewGuid ( ) ;
1088
+ initialEntities . Add ( childEntity2 ) ;
1089
+
1090
+ XrmFakedContext context = new XrmFakedContext ( ) ;
1091
+ IOrganizationService service = context . GetOrganizationService ( ) ;
1092
+
1093
+ context . Initialize ( initialEntities ) ;
1094
+
1095
+ // the query selects the "parent" entity, and joins to the "child" entities
1096
+ QueryExpression query = new QueryExpression ( "parent" ) ;
1097
+ query . ColumnSet = new ColumnSet ( "parentname" ) ;
1098
+
1099
+ LinkEntity link = new LinkEntity ( "parent" , "child" , "parentid" , "parent" , JoinOperator . Inner ) ;
1100
+ link . EntityAlias = "c" ;
1101
+ link . Columns = new ColumnSet ( "name" , "myvalue" ) ;
1102
+
1103
+ query . LinkEntities . Add ( link ) ;
1104
+
1105
+ // ACT
1106
+
1107
+ DataCollection < Entity > results = service . RetrieveMultiple ( query ) . Entities ;
1108
+
1109
+ // ASSERT
1110
+
1111
+ // fields for the first entity work as expected...
1112
+ string entity1Name = results [ 0 ] . GetAttributeValue < AliasedValue > ( "c.name" ) . Value as string ;
1113
+ string entity1Value = results [ 0 ] . GetAttributeValue < AliasedValue > ( "c.myvalue" ) . Value as string ;
1114
+
1115
+ Assert . Equal ( "entity1" , entity1Name ) ;
1116
+ Assert . Equal ( "value" , entity1Value ) ;
1117
+
1118
+ // fields for the second entity do not.
1119
+ // The child "name" field is correct, but the "myvalue" field is returning the value of the previous
1120
+ // entity when it should be returning null
1121
+ string entity2Name = results [ 1 ] . GetAttributeValue < AliasedValue > ( "c.name" ) . Value as string ;
1122
+ string entity2Value = results [ 1 ] . GetAttributeValue < AliasedValue > ( "c.myvalue" ) ? . Value as string ;
1123
+
1124
+ // this works fine:
1125
+ Assert . Equal ( "entity2" , entity2Name ) ;
1126
+
1127
+ // this fails (entity2Value is "value")
1128
+ Assert . Equal ( null , entity2Value ) ;
1129
+ }
1061
1130
}
1062
1131
}
0 commit comments