Skip to content

Commit e7a5520

Browse files
committed
Provided handling of potentially null topic references
Now that `TopicReference.Value` is `null`, iterations over `Topic.References` must account for that possibility. That has always been done when calling `GetTopic()` (now `GetValue()`), but not when iterating over the collection.
1 parent e91a006 commit e7a5520

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ topic.References.Count is 0?
282282
from reference in topic.References
283283
select new XElement(_pagemapNamespace + "Attribute",
284284
new XAttribute("name", reference.Key),
285-
new XText(reference.Value.GetUniqueKey().Replace("Root:", "", StringComparison.OrdinalIgnoreCase))
285+
new XText(reference.Value?.GetUniqueKey().Replace("Root:", "", StringComparison.OrdinalIgnoreCase))
286286
)
287287
);
288288

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ private static void PersistReferences(Topic topic, DateTime version, SqlConnecti
710710
CommandType = CommandType.StoredProcedure
711711
};
712712

713-
foreach (var relatedTopic in topic.References.Where(t => !t.Value.IsNew)) {
714-
references.AddRow(relatedTopic.Key, relatedTopic.Value.Id);
713+
foreach (var relatedTopic in topic.References.Where(t => !t.Value?.IsNew?? false)) {
714+
references.AddRow(relatedTopic.Key, relatedTopic.Value!.Id);
715715
}
716716

717717
// Add Parameters

OnTopic/Repositories/TopicRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private void Save([NotNull]Topic topic, bool isRecursive, TopicCollection unreso
349349
\-----------------------------------------------------------------------------------------------------------------------*/
350350
if (
351351
topic.Relationships.Any(r => r.Values.Any(t => t.Id < 0)) ||
352-
topic.References.Values.Any(t => t.Id < 0)
352+
topic.References.Any(t => t.Value?.Id < 0)
353353
) {
354354
unresolvedTopics.Add(topic);
355355
}

0 commit comments

Comments
 (0)