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

Commit

Permalink
Fix DeleteById with RowVersion for SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jul 24, 2018
1 parent 76b0ced commit af3a2cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace ServiceStack.OrmLite.SqlServer.Converters
{
public class SqlServerRowVersionConverter : RowVersionConverter
{
public override string ColumnDefinition
{
get { return "rowversion"; }
}
public override string ColumnDefinition => "rowversion";
}
}
3 changes: 3 additions & 0 deletions src/ServiceStack.OrmLite/OrmLiteWriteCommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ internal static string DeleteByIdSql<T>(this IDbCommand dbCmd, object id, ulong

var rowVersionParam = dbCmd.CreateParameter();
rowVersionParam.ParameterName = dialectProvider.GetParam("rowVersion");
var converter = dialectProvider.GetConverterBestMatch(typeof(ulong));
converter.InitDbParam(rowVersionParam, typeof(ulong));

rowVersionParam.Value = rowVersion;
dbCmd.Parameters.Add(rowVersionParam);

Expand Down
12 changes: 12 additions & 0 deletions tests/ServiceStack.OrmLite.Tests/RowVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ public void Can_delete_with_current_rowversion()
var count = db.Count<ModelWithRowVersion>(m => m.Id == rowId);
Assert.That(count, Is.EqualTo(0));
}

[Test]
public void Can_DeleteById_with_current_rowversion()
{
var rowId = db.Insert(new ModelWithRowVersion { Text = "Four" }, selectIdentity: true);
var row = db.SingleById<ModelWithRowVersion>(rowId);

db.DeleteById<ModelWithRowVersion>(row.Id, rowVersion:row.RowVersion);

var count = db.Count<ModelWithRowVersion>(m => m.Id == rowId);
Assert.That(count, Is.EqualTo(0));
}

[Test]
public void Update_with_outdated_rowversion_throws()
Expand Down

0 comments on commit af3a2cd

Please sign in to comment.