@@ -26,7 +26,8 @@ public Document Build(IIdentifiable entity)
2626 var document = new Document
2727 {
2828 Data = _getData ( contextEntity , entity ) ,
29- Meta = _getMeta ( entity )
29+ Meta = _getMeta ( entity ) ,
30+ Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) )
3031 } ;
3132
3233 document . Included = _appendIncludedObject ( document . Included , contextEntity , entity ) ;
@@ -45,7 +46,8 @@ public Documents Build(IEnumerable<IIdentifiable> entities)
4546 var documents = new Documents
4647 {
4748 Data = new List < DocumentData > ( ) ,
48- Meta = _getMeta ( entities . FirstOrDefault ( ) )
49+ Meta = _getMeta ( entities . FirstOrDefault ( ) ) ,
50+ Links = _jsonApiContext . PageManager . GetPageLinks ( new LinkBuilder ( _jsonApiContext ) )
4951 } ;
5052
5153 foreach ( var entity in entities )
@@ -68,7 +70,7 @@ private Dictionary<string, object> _getMeta(IIdentifiable entity)
6870 meta = metaEntity . GetMeta ( _jsonApiContext ) ;
6971
7072 if ( _jsonApiContext . Options . IncludeTotalRecordCount )
71- meta [ "total-records" ] = _jsonApiContext . TotalRecords ;
73+ meta [ "total-records" ] = _jsonApiContext . PageManager . TotalRecords ;
7274
7375 if ( meta . Count > 0 ) return meta ;
7476 return null ;
@@ -122,23 +124,25 @@ private void _addRelationships(DocumentData data, ContextEntity contextEntity, I
122124 {
123125 Links = new Links
124126 {
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 )
127129 }
128130 } ;
129131
130- if ( _relationshipIsIncluded ( r . RelationshipName ) )
132+ if ( _relationshipIsIncluded ( r . InternalRelationshipName ) )
131133 {
132134 var navigationEntity = _jsonApiContext . ContextGraph
133- . GetRelationship ( entity , r . RelationshipName ) ;
135+ . GetRelationship ( entity , r . InternalRelationshipName ) ;
134136
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 ) ;
137141 else
138- relationshipData . SingleData = _getRelationship ( navigationEntity , r . RelationshipName ) ;
142+ relationshipData . SingleData = _getRelationship ( navigationEntity , r . InternalRelationshipName ) ;
139143 }
140144
141- data . Relationships . Add ( r . RelationshipName . Dasherize ( ) , relationshipData ) ;
145+ data . Relationships . Add ( r . InternalRelationshipName . Dasherize ( ) , relationshipData ) ;
142146 } ) ;
143147 }
144148
@@ -148,9 +152,9 @@ private List<DocumentData> _getIncludedEntities(ContextEntity contextEntity, IId
148152
149153 contextEntity . Relationships . ForEach ( r =>
150154 {
151- if ( ! _relationshipIsIncluded ( r . RelationshipName ) ) return ;
155+ if ( ! _relationshipIsIncluded ( r . InternalRelationshipName ) ) return ;
152156
153- var navigationEntity = _jsonApiContext . ContextGraph . GetRelationship ( entity , r . RelationshipName ) ;
157+ var navigationEntity = _jsonApiContext . ContextGraph . GetRelationship ( entity , r . InternalRelationshipName ) ;
154158
155159 if ( navigationEntity is IEnumerable )
156160 foreach ( var includedEntity in ( IEnumerable ) navigationEntity )
@@ -164,6 +168,8 @@ private List<DocumentData> _getIncludedEntities(ContextEntity contextEntity, IId
164168
165169 private DocumentData _getIncludedEntity ( IIdentifiable entity )
166170 {
171+ if ( entity == null ) return null ;
172+
167173 var contextEntity = _jsonApiContext . ContextGraph . GetContextEntity ( entity . GetType ( ) ) ;
168174
169175 var data = new DocumentData
0 commit comments