1414using Microsoft . Data . SqlClient ;
1515using OnTopic . Data . Sql . Models ;
1616using OnTopic . Internal . Diagnostics ;
17- using OnTopic . Metadata ;
1817using OnTopic . Repositories ;
1918
2019namespace OnTopic . Data . Sql {
@@ -269,6 +268,7 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
269268 /*------------------------------------------------------------------------------------------------------------------------
270269 | Establish dependencies
271270 \-----------------------------------------------------------------------------------------------------------------------*/
271+ var version = new SqlDateTime ( DateTime . Now ) ;
272272 var unresolvedTopics = new List < Topic > ( ) ;
273273 var connection = new SqlConnection ( _connectionString ) ;
274274
@@ -277,13 +277,13 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
277277 /*------------------------------------------------------------------------------------------------------------------------
278278 | Handle first pass
279279 \-----------------------------------------------------------------------------------------------------------------------*/
280- var topicId = Save ( topic , isRecursive , isDraft , connection , unresolvedTopics ) ;
280+ var topicId = Save ( topic , isRecursive , isDraft , connection , unresolvedTopics , version ) ;
281281
282282 /*------------------------------------------------------------------------------------------------------------------------
283283 | Attempt to resolve outstanding relationships
284284 \-----------------------------------------------------------------------------------------------------------------------*/
285285 foreach ( var unresolvedTopic in unresolvedTopics ) {
286- Save ( unresolvedTopic , false , isDraft , connection , new List < Topic > ( ) ) ;
286+ Save ( unresolvedTopic , false , isDraft , connection , new List < Topic > ( ) , version ) ;
287287 }
288288
289289 /*------------------------------------------------------------------------------------------------------------------------
@@ -325,7 +325,8 @@ private int Save(
325325 bool isRecursive ,
326326 bool isDraft ,
327327 SqlConnection connection ,
328- List < Topic > unresolvedRelationships
328+ List < Topic > unresolvedRelationships ,
329+ SqlDateTime version
329330 ) {
330331
331332 /*------------------------------------------------------------------------------------------------------------------------
@@ -337,7 +338,6 @@ List<Topic> unresolvedRelationships
337338 | Define variables
338339 \-----------------------------------------------------------------------------------------------------------------------*/
339340 var isNew = topic . Id == - 1 ;
340- var version = new SqlDateTime ( DateTime . Now ) ;
341341 var areReferencesResolved = true ;
342342 var areRelationshipsDirty = topic . Relationships . IsDirty ( ) ;
343343 var areAttributesDirty = topic . Attributes . IsDirty ( excludeLastModified : true ) ;
@@ -468,7 +468,9 @@ List<Topic> unresolvedRelationships
468468 PersistRelations ( topic , connection ) ;
469469 }
470470
471- topic . VersionHistory . Insert ( 0 , version . Value ) ;
471+ if ( ! topic . VersionHistory . Contains ( version . Value ) ) {
472+ topic . VersionHistory . Insert ( 0 , version . Value ) ;
473+ }
472474
473475 }
474476
@@ -504,7 +506,7 @@ void recurse() {
504506 if ( isRecursive ) {
505507 foreach ( var childTopic in topic . Children ) {
506508 childTopic . Attributes . SetValue ( "ParentID" , topic . Id . ToString ( CultureInfo . InvariantCulture ) ) ;
507- Save ( childTopic , isRecursive , isDraft , connection , unresolvedRelationships ) ;
509+ Save ( childTopic , isRecursive , isDraft , connection , unresolvedRelationships , version ) ;
508510 }
509511 }
510512 }
0 commit comments