@@ -26,7 +26,8 @@ public Document Build(IIdentifiable entity)
26
26
var document = new Document
27
27
{
28
28
Data = _getData ( contextEntity , entity ) ,
29
- Meta = _getMeta ( entity )
29
+ Meta = _getMeta ( entity ) ,
30
+ Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) )
30
31
} ;
31
32
32
33
document . Included = _appendIncludedObject ( document . Included , contextEntity , entity ) ;
@@ -45,7 +46,8 @@ public Documents Build(IEnumerable<IIdentifiable> entities)
45
46
var documents = new Documents
46
47
{
47
48
Data = new List < DocumentData > ( ) ,
48
- Meta = _getMeta ( entities . FirstOrDefault ( ) )
49
+ Meta = _getMeta ( entities . FirstOrDefault ( ) ) ,
50
+ Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) )
49
51
} ;
50
52
51
53
foreach ( var entity in entities )
@@ -68,7 +70,7 @@ private Dictionary<string, object> _getMeta(IIdentifiable entity)
68
70
meta = metaEntity . GetMeta ( _jsonApiContext ) ;
69
71
70
72
if ( _jsonApiContext . Options . IncludeTotalRecordCount )
71
- meta [ "total-records" ] = _jsonApiContext . TotalRecords ;
73
+ meta [ "total-records" ] = _jsonApiContext . PageManager . TotalRecords ;
72
74
73
75
if ( meta . Count > 0 ) return meta ;
74
76
return null ;
@@ -122,23 +124,25 @@ private void _addRelationships(DocumentData data, ContextEntity contextEntity, I
122
124
{
123
125
Links = new Links
124
126
{
125
- Self = linkBuilder . GetSelfRelationLink ( contextEntity . EntityName , entity . Id . ToString ( ) , r . RelationshipName ) ,
126
- Related = linkBuilder . GetRelatedRelationLink ( contextEntity . EntityName , entity . Id . ToString ( ) , r . RelationshipName )
127
+ Self = linkBuilder . GetSelfRelationLink ( contextEntity . EntityName , entity . Id . ToString ( ) , r . InternalRelationshipName ) ,
128
+ Related = linkBuilder . GetRelatedRelationLink ( contextEntity . EntityName , entity . Id . ToString ( ) , r . InternalRelationshipName )
127
129
}
128
130
} ;
129
131
130
- if ( _relationshipIsIncluded ( r . RelationshipName ) )
132
+ if ( _relationshipIsIncluded ( r . InternalRelationshipName ) )
131
133
{
132
134
var navigationEntity = _jsonApiContext . ContextGraph
133
- . GetRelationship ( entity , r . RelationshipName ) ;
135
+ . GetRelationship ( entity , r . InternalRelationshipName ) ;
134
136
135
- if ( navigationEntity is IEnumerable )
136
- relationshipData . ManyData = _getRelationships ( ( IEnumerable < object > ) navigationEntity , r . RelationshipName ) ;
137
+ if ( navigationEntity == null )
138
+ relationshipData . SingleData = null ;
139
+ else if ( navigationEntity is IEnumerable )
140
+ relationshipData . ManyData = _getRelationships ( ( IEnumerable < object > ) navigationEntity , r . InternalRelationshipName ) ;
137
141
else
138
- relationshipData . SingleData = _getRelationship ( navigationEntity , r . RelationshipName ) ;
142
+ relationshipData . SingleData = _getRelationship ( navigationEntity , r . InternalRelationshipName ) ;
139
143
}
140
144
141
- data . Relationships . Add ( r . RelationshipName . Dasherize ( ) , relationshipData ) ;
145
+ data . Relationships . Add ( r . InternalRelationshipName . Dasherize ( ) , relationshipData ) ;
142
146
} ) ;
143
147
}
144
148
@@ -148,9 +152,9 @@ private List<DocumentData> _getIncludedEntities(ContextEntity contextEntity, IId
148
152
149
153
contextEntity . Relationships . ForEach ( r =>
150
154
{
151
- if ( ! _relationshipIsIncluded ( r . RelationshipName ) ) return ;
155
+ if ( ! _relationshipIsIncluded ( r . InternalRelationshipName ) ) return ;
152
156
153
- var navigationEntity = _jsonApiContext . ContextGraph . GetRelationship ( entity , r . RelationshipName ) ;
157
+ var navigationEntity = _jsonApiContext . ContextGraph . GetRelationship ( entity , r . InternalRelationshipName ) ;
154
158
155
159
if ( navigationEntity is IEnumerable )
156
160
foreach ( var includedEntity in ( IEnumerable ) navigationEntity )
@@ -164,6 +168,8 @@ private List<DocumentData> _getIncludedEntities(ContextEntity contextEntity, IId
164
168
165
169
private DocumentData _getIncludedEntity ( IIdentifiable entity )
166
170
{
171
+ if ( entity == null ) return null ;
172
+
167
173
var contextEntity = _jsonApiContext . ContextGraph . GetContextEntity ( entity . GetType ( ) ) ;
168
174
169
175
var data = new DocumentData
0 commit comments