@@ -36,7 +36,7 @@ public Document Build(IIdentifiable entity)
36
36
Meta = GetMeta ( entity )
37
37
} ;
38
38
39
- if ( ShouldIncludePageLinks ( contextEntity ) )
39
+ if ( ShouldIncludePageLinks ( contextEntity ) )
40
40
document . Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) ) ;
41
41
42
42
document . Included = AppendIncludedObject ( document . Included , contextEntity , entity ) ;
@@ -59,7 +59,7 @@ public Documents Build(IEnumerable<IIdentifiable> entities)
59
59
Meta = GetMeta ( enumeratedEntities . FirstOrDefault ( ) )
60
60
} ;
61
61
62
- if ( ShouldIncludePageLinks ( contextEntity ) )
62
+ if ( ShouldIncludePageLinks ( contextEntity ) )
63
63
documents . Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) ) ;
64
64
65
65
foreach ( var entity in enumeratedEntities )
@@ -74,20 +74,20 @@ public Documents Build(IEnumerable<IIdentifiable> entities)
74
74
private Dictionary < string , object > GetMeta ( IIdentifiable entity )
75
75
{
76
76
if ( entity == null ) return null ;
77
-
77
+
78
78
var builder = _jsonApiContext . MetaBuilder ;
79
79
80
- if ( entity is IHasMeta metaEntity )
80
+ if ( entity is IHasMeta metaEntity )
81
81
builder . Add ( metaEntity . GetMeta ( _jsonApiContext ) ) ;
82
82
83
- if ( _jsonApiContext . Options . IncludeTotalRecordCount )
83
+ if ( _jsonApiContext . Options . IncludeTotalRecordCount )
84
84
builder . Add ( "total-records" , _jsonApiContext . PageManager . TotalRecords ) ;
85
-
86
- if ( _requestMeta != null )
85
+
86
+ if ( _requestMeta != null )
87
87
builder . Add ( _requestMeta . GetMeta ( ) ) ;
88
88
89
89
var meta = builder . Build ( ) ;
90
- if ( meta . Count > 0 ) return meta ;
90
+ if ( meta . Count > 0 ) return meta ;
91
91
return null ;
92
92
}
93
93
@@ -119,7 +119,7 @@ public DocumentData GetData(ContextEntity contextEntity, IIdentifiable entity)
119
119
120
120
contextEntity . Attributes . ForEach ( attr =>
121
121
{
122
- if ( ShouldIncludeAttribute ( attr ) )
122
+ if ( ShouldIncludeAttribute ( attr ) )
123
123
data . Attributes . Add ( attr . PublicAttributeName , attr . GetValue ( entity ) ) ;
124
124
} ) ;
125
125
@@ -131,8 +131,8 @@ public DocumentData GetData(ContextEntity contextEntity, IIdentifiable entity)
131
131
132
132
private bool ShouldIncludeAttribute ( AttrAttribute attr )
133
133
{
134
- return ( _jsonApiContext . QuerySet == null
135
- || _jsonApiContext . QuerySet . Fields . Count == 0
134
+ return ( _jsonApiContext . QuerySet == null
135
+ || _jsonApiContext . QuerySet . Fields . Count == 0
136
136
|| _jsonApiContext . QuerySet . Fields . Contains ( attr . InternalAttributeName ) ) ;
137
137
}
138
138
@@ -145,13 +145,13 @@ private void AddRelationships(DocumentData data, ContextEntity contextEntity, II
145
145
{
146
146
var relationshipData = new RelationshipData ( ) ;
147
147
148
- if ( r . DocumentLinks . HasFlag ( Link . None ) == false )
148
+ if ( r . DocumentLinks . HasFlag ( Link . None ) == false )
149
149
{
150
150
relationshipData . Links = new Links ( ) ;
151
- if ( r . DocumentLinks . HasFlag ( Link . Self ) )
151
+ if ( r . DocumentLinks . HasFlag ( Link . Self ) )
152
152
relationshipData . Links . Self = linkBuilder . GetSelfRelationLink ( contextEntity . EntityName , entity . StringId , r . PublicRelationshipName ) ;
153
-
154
- if ( r . DocumentLinks . HasFlag ( Link . Related ) )
153
+
154
+ if ( r . DocumentLinks . HasFlag ( Link . Related ) )
155
155
relationshipData . Links . Related = linkBuilder . GetRelatedRelationLink ( contextEntity . EntityName , entity . StringId , r . PublicRelationshipName ) ;
156
156
}
157
157
@@ -160,7 +160,7 @@ private void AddRelationships(DocumentData data, ContextEntity contextEntity, II
160
160
var navigationEntity = _jsonApiContext . ContextGraph
161
161
. GetRelationship ( entity , r . InternalRelationshipName ) ;
162
162
163
- if ( navigationEntity == null )
163
+ if ( navigationEntity == null )
164
164
relationshipData . SingleData = null ;
165
165
else if ( navigationEntity is IEnumerable )
166
166
relationshipData . ManyData = GetRelationships ( ( IEnumerable < object > ) navigationEntity ) ;
@@ -194,19 +194,22 @@ private List<DocumentData> AddIncludedEntity(List<DocumentData> entities, IIdent
194
194
{
195
195
var includedEntity = GetIncludedEntity ( entity ) ;
196
196
197
- if ( entities == null )
197
+ if ( entities == null )
198
198
entities = new List < DocumentData > ( ) ;
199
199
200
- if ( includedEntity != null && ! entities . Any ( doc => doc . Id == includedEntity . Id && doc . Type == includedEntity . Type ) )
200
+ if ( includedEntity != null && entities . Any ( doc =>
201
+ string . Equals ( doc . Id , includedEntity . Id ) && string . Equals ( doc . Type , includedEntity . Type ) ) == false )
202
+ {
201
203
entities . Add ( includedEntity ) ;
204
+ }
202
205
203
206
return entities ;
204
207
}
205
208
206
209
private DocumentData GetIncludedEntity ( IIdentifiable entity )
207
210
{
208
- if ( entity == null ) return null ;
209
-
211
+ if ( entity == null ) return null ;
212
+
210
213
var contextEntity = _jsonApiContext . ContextGraph . GetContextEntity ( entity . GetType ( ) ) ;
211
214
212
215
var data = GetData ( contextEntity , entity ) ;
0 commit comments