Skip to content

Commit d0a96d8

Browse files
committed
Bypass unsaved relationships
Typically, relationships will point to established topic entities that have been saved. When saving large topic graphs, however, relationships may point to topics which have not yet been saved—in which case they will be pointing to a topic with the `Id` of `-1`. If this is persisted to the database, a foreign key violation will occur. This is a known limitation of the library, which currently requires calling `Save()` twice in these scenarios. That's an unfortunate if edge scenario. But that scenario should not yield FKC violations on the initial `Save()`. To mitigate that, we'll just ignore any relationships pointing to an unsaved `Topic`.
1 parent 852a33e commit d0a96d8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ private static string PersistRelations(Topic topic, SqlConnection connection, bo
585585
var scope = topic.Relationships.GetTopics(key);
586586
var topicId = topic.Id.ToString(CultureInfo.InvariantCulture);
587587

588+
//Relationship hasn't been saved yet; cannot persist
589+
if (topic.Id < 0) {
590+
continue;
591+
}
592+
588593
command = new SqlCommand("UpdateRelationships", connection) {
589594
CommandType = CommandType.StoredProcedure
590595
};

0 commit comments

Comments
 (0)