@@ -337,7 +337,6 @@ SqlDateTime version
337337 /*------------------------------------------------------------------------------------------------------------------------
338338 | Define variables
339339 \-----------------------------------------------------------------------------------------------------------------------*/
340- var isNew = topic . Id == - 1 ;
341340 var areReferencesResolved = true ;
342341 var areRelationshipsDirty = topic . Relationships . IsDirty ( ) ;
343342 var areAttributesDirty = topic . Attributes . IsDirty ( excludeLastModified : ! areRelationshipsDirty ) ;
@@ -418,7 +417,7 @@ SqlDateTime version
418417 /*------------------------------------------------------------------------------------------------------------------------
419418 | Establish database connection
420419 \-----------------------------------------------------------------------------------------------------------------------*/
421- var procedureName = isNew ? "CreateTopic" : "UpdateTopic" ;
420+ var procedureName = ! topic . IsSaved ? "CreateTopic" : "UpdateTopic" ;
422421 var command = new SqlCommand ( procedureName , connection ) {
423422 CommandType = CommandType . StoredProcedure
424423 } ;
@@ -438,7 +437,7 @@ SqlDateTime version
438437 /*------------------------------------------------------------------------------------------------------------------------
439438 | Establish query parameters
440439 \-----------------------------------------------------------------------------------------------------------------------*/
441- if ( ! isNew ) {
440+ if ( topic . IsSaved ) {
442441 command . AddParameter ( "TopicID" , topic . Id ) ;
443442 command . AddParameter ( "DeleteRelationships" , areReferencesResolved && areRelationshipsDirty ) ;
444443 }
@@ -460,7 +459,7 @@ SqlDateTime version
460459 topic . Id = command . GetReturnCode ( ) ;
461460
462461 Contract . Assume < InvalidOperationException > (
463- topic . Id > 0 ,
462+ topic . IsSaved ,
464463 "The call to the CreateTopic stored procedure did not return the expected 'Id' parameter."
465464 ) ;
466465
@@ -657,7 +656,7 @@ private static void PersistRelations(Topic topic, SqlConnection connection) {
657656 var targetIds = new TopicListDataTable ( ) ;
658657 var relatedTopics = topic . Relationships . GetTopics ( key ) ;
659658 var topicId = topic . Id . ToString ( CultureInfo . InvariantCulture ) ;
660- var savedTopics = relatedTopics . Where ( t => t . Id > 0 ) . Select < Topic , int > ( m => m . Id ) ;
659+ var savedTopics = relatedTopics . Where ( t => t . IsSaved ) . Select < Topic , int > ( m => m . Id ) ;
661660
662661 command = new SqlCommand ( "UpdateRelationships" , connection ) {
663662 CommandType = CommandType . StoredProcedure
0 commit comments