Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit af3a2cd

Browse files
committed
Fix DeleteById with RowVersion for SQL Server
1 parent 76b0ced commit af3a2cd

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/ServiceStack.OrmLite.SqlServer/Converters/SqlServerSpecialConverters.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ namespace ServiceStack.OrmLite.SqlServer.Converters
44
{
55
public class SqlServerRowVersionConverter : RowVersionConverter
66
{
7-
public override string ColumnDefinition
8-
{
9-
get { return "rowversion"; }
10-
}
7+
public override string ColumnDefinition => "rowversion";
118
}
129
}

src/ServiceStack.OrmLite/OrmLiteWriteCommandExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ internal static string DeleteByIdSql<T>(this IDbCommand dbCmd, object id, ulong
573573

574574
var rowVersionParam = dbCmd.CreateParameter();
575575
rowVersionParam.ParameterName = dialectProvider.GetParam("rowVersion");
576+
var converter = dialectProvider.GetConverterBestMatch(typeof(ulong));
577+
converter.InitDbParam(rowVersionParam, typeof(ulong));
578+
576579
rowVersionParam.Value = rowVersion;
577580
dbCmd.Parameters.Add(rowVersionParam);
578581

tests/ServiceStack.OrmLite.Tests/RowVersionTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,18 @@ public void Can_delete_with_current_rowversion()
360360
var count = db.Count<ModelWithRowVersion>(m => m.Id == rowId);
361361
Assert.That(count, Is.EqualTo(0));
362362
}
363+
364+
[Test]
365+
public void Can_DeleteById_with_current_rowversion()
366+
{
367+
var rowId = db.Insert(new ModelWithRowVersion { Text = "Four" }, selectIdentity: true);
368+
var row = db.SingleById<ModelWithRowVersion>(rowId);
369+
370+
db.DeleteById<ModelWithRowVersion>(row.Id, rowVersion:row.RowVersion);
371+
372+
var count = db.Count<ModelWithRowVersion>(m => m.Id == rowId);
373+
Assert.That(count, Is.EqualTo(0));
374+
}
363375

364376
[Test]
365377
public void Update_with_outdated_rowversion_throws()

0 commit comments

Comments
 (0)