@@ -95,12 +95,10 @@ private Dictionary<string, object> GetMeta(IIdentifiable entity)
95
95
96
96
private List < DocumentData > AppendIncludedObject ( List < DocumentData > includedObject , ContextEntity contextEntity , IIdentifiable entity )
97
97
{
98
- var includedEntities = GetIncludedEntities ( contextEntity , entity ) ;
99
- if ( includedEntities . Count > 0 )
98
+ var includedEntities = GetIncludedEntities ( includedObject , contextEntity , entity ) ;
99
+ if ( includedEntities ? . Count > 0 )
100
100
{
101
- if ( includedObject == null )
102
- includedObject = new List < DocumentData > ( ) ;
103
- includedObject . AddRange ( includedEntities ) ;
101
+ includedObject = includedEntities ;
104
102
}
105
103
106
104
return includedObject ;
@@ -174,10 +172,8 @@ private void AddRelationships(DocumentData data, ContextEntity contextEntity, II
174
172
} ) ;
175
173
}
176
174
177
- private List < DocumentData > GetIncludedEntities ( ContextEntity contextEntity , IIdentifiable entity )
175
+ private List < DocumentData > GetIncludedEntities ( List < DocumentData > included , ContextEntity contextEntity , IIdentifiable entity )
178
176
{
179
- var included = new List < DocumentData > ( ) ;
180
-
181
177
contextEntity . Relationships . ForEach ( r =>
182
178
{
183
179
if ( ! RelationshipIsIncluded ( r . PublicRelationshipName ) ) return ;
@@ -186,20 +182,25 @@ private List<DocumentData> GetIncludedEntities(ContextEntity contextEntity, IIde
186
182
187
183
if ( navigationEntity is IEnumerable hasManyNavigationEntity )
188
184
foreach ( IIdentifiable includedEntity in hasManyNavigationEntity )
189
- AddIncludedEntity ( included , includedEntity ) ;
185
+ included = AddIncludedEntity ( included , includedEntity ) ;
190
186
else
191
- AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity ) ;
187
+ included = AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity ) ;
192
188
} ) ;
193
189
194
190
return included ;
195
191
}
196
192
197
- private void AddIncludedEntity ( List < DocumentData > entities , IIdentifiable entity )
193
+ private List < DocumentData > AddIncludedEntity ( List < DocumentData > entities , IIdentifiable entity )
198
194
{
199
195
var includedEntity = GetIncludedEntity ( entity ) ;
200
196
197
+ if ( entities == null )
198
+ entities = new List < DocumentData > ( ) ;
199
+
201
200
if ( includedEntity != null && ! entities . Any ( doc => doc . Id == includedEntity . Id && doc . Type == includedEntity . Type ) )
202
201
entities . Add ( includedEntity ) ;
202
+
203
+ return entities ;
203
204
}
204
205
205
206
private DocumentData GetIncludedEntity ( IIdentifiable entity )
0 commit comments