Skip to content

Commit 8847403

Browse files
committed
fix(JsonApiDeSerializer): allow empty collection
Sequence contains no matching element
1 parent d930c5b commit 8847403

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ private object SetHasOneRelationship(object entity,
221221
var contextGraphEntity = _jsonApiContext.ContextGraph.GetContextEntity(attr.Type);
222222
if(navigationPropertyValue != null && contextGraphEntity != null)
223223
{
224-
var includedResource = included.Single(r => r.Type == rio.Type && r.Id == rio.Id);
225-
SetRelationships(navigationPropertyValue, contextGraphEntity, includedResource.Relationships, included);
224+
var includedResource = included.SingleOrDefault(r => r.Type == rio.Type && r.Id == rio.Id);
225+
if(includedResource != null)
226+
SetRelationships(navigationPropertyValue, contextGraphEntity, includedResource.Relationships, included);
226227
}
227228
}
228229

0 commit comments

Comments
 (0)