Skip to content

Commit ab19b9d

Browse files
committed
Fix logic mixup with newly introduced procedureName variable
When I introduced the new `procedureName` variable to track whether the `Save()` was calling `CreateTopic` or `UpdateTopic` (#ac6c2ba6), I accidentally got the logic wrong. As a result, `CreateTopic` was being called for new topics, and `UpdateTopic` for existing topics—which caused a mismatch with the parameters. Oops. To fix this, I now use the recently introduced `isNew` variable (#36ca32d), which is a bit more semantically intuitive than `topic.Id > 0`.
1 parent 7ca6c0e commit ab19b9d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,13 @@ public override int Save([NotNull]Topic topic, bool isRecursive = false, bool is
327327
/*------------------------------------------------------------------------------------------------------------------------
328328
| Establish database connection
329329
\-----------------------------------------------------------------------------------------------------------------------*/
330+
var isNew = topic.Id == -1;
330331
var connection = new SqlConnection(_connectionString);
331-
var procedureName = topic.Id > 0? "CreateTopic" : "UpdateTopic";
332+
var procedureName = isNew? "CreateTopic" : "UpdateTopic";
332333
var command = new SqlCommand(procedureName, connection) {
333334
CommandType = CommandType.StoredProcedure
334335
};
335336
var version = DateTime.Now;
336-
var isNew = topic.Id == -1;
337337

338338
/*------------------------------------------------------------------------------------------------------------------------
339339
| Establish query parameters

0 commit comments

Comments
 (0)