@@ -95,12 +95,10 @@ private Dictionary<string, object> GetMeta(IIdentifiable entity)
9595
9696 private List < DocumentData > AppendIncludedObject ( List < DocumentData > includedObject , ContextEntity contextEntity , IIdentifiable entity )
9797 {
98- var includedEntities = GetIncludedEntities ( contextEntity , entity ) ;
99- if ( includedEntities . Count > 0 )
98+ var includedEntities = GetIncludedEntities ( includedObject , contextEntity , entity ) ;
99+ if ( includedEntities ? . Count > 0 )
100100 {
101- if ( includedObject == null )
102- includedObject = new List < DocumentData > ( ) ;
103- includedObject . AddRange ( includedEntities ) ;
101+ includedObject = includedEntities ;
104102 }
105103
106104 return includedObject ;
@@ -174,10 +172,8 @@ private void AddRelationships(DocumentData data, ContextEntity contextEntity, II
174172 } ) ;
175173 }
176174
177- private List < DocumentData > GetIncludedEntities ( ContextEntity contextEntity , IIdentifiable entity )
175+ private List < DocumentData > GetIncludedEntities ( List < DocumentData > included , ContextEntity contextEntity , IIdentifiable entity )
178176 {
179- var included = new List < DocumentData > ( ) ;
180-
181177 contextEntity . Relationships . ForEach ( r =>
182178 {
183179 if ( ! RelationshipIsIncluded ( r . PublicRelationshipName ) ) return ;
@@ -186,20 +182,25 @@ private List<DocumentData> GetIncludedEntities(ContextEntity contextEntity, IIde
186182
187183 if ( navigationEntity is IEnumerable hasManyNavigationEntity )
188184 foreach ( IIdentifiable includedEntity in hasManyNavigationEntity )
189- AddIncludedEntity ( included , includedEntity ) ;
185+ included = AddIncludedEntity ( included , includedEntity ) ;
190186 else
191- AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity ) ;
187+ included = AddIncludedEntity ( included , ( IIdentifiable ) navigationEntity ) ;
192188 } ) ;
193189
194190 return included ;
195191 }
196192
197- private void AddIncludedEntity ( List < DocumentData > entities , IIdentifiable entity )
193+ private List < DocumentData > AddIncludedEntity ( List < DocumentData > entities , IIdentifiable entity )
198194 {
199195 var includedEntity = GetIncludedEntity ( entity ) ;
200196
197+ if ( entities == null )
198+ entities = new List < DocumentData > ( ) ;
199+
201200 if ( includedEntity != null && ! entities . Any ( doc => doc . Id == includedEntity . Id && doc . Type == includedEntity . Type ) )
202201 entities . Add ( includedEntity ) ;
202+
203+ return entities ;
203204 }
204205
205206 private DocumentData GetIncludedEntity ( IIdentifiable entity )
0 commit comments