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

Commit 75b6a2d

Browse files
committed
Fix RowVersion for SqlServer
1 parent 9c3721d commit 75b6a2d

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

lib/ServiceStack.Text.dll

1.5 KB
Binary file not shown.

lib/ServiceStack.Text.pdb

2 KB
Binary file not shown.

src/ServiceStack.OrmLite.SqlServer/SqlServerOrmLiteDialectProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ public override void SetDbValue(FieldDefinition fieldDef, IDataReader reader, in
107107
var bytes = reader.GetValue(colIndex) as byte[];
108108
if (bytes != null)
109109
{
110-
Array.Reverse(bytes); //Correct Endianness
111-
var ulongValue = BitConverter.ToUInt64(bytes, 0);
110+
var ulongValue = ConvertToULong(bytes);
112111
try
113112
{
114113
fieldDef.SetValueFn(instance, ulongValue);

src/ServiceStack.OrmLite/OrmLiteDialectProviderBase.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,14 @@ protected virtual string FkOptionToString(OnFkOption option)
12451245
}
12461246
}
12471247

1248+
1249+
public static ulong ConvertToULong(byte[] bytes)
1250+
{
1251+
Array.Reverse(bytes); //Correct Endianness
1252+
var ulongValue = BitConverter.ToUInt64(bytes, 0);
1253+
return ulongValue;
1254+
}
1255+
12481256
public virtual object ConvertDbValue(object value, Type type)
12491257
{
12501258
if (value == null || value is DBNull) return null;
@@ -1289,7 +1297,12 @@ public virtual object ConvertDbValue(object value, Type type)
12891297
case TypeCode.Int64:
12901298
return value is long ? value : Convert.ToInt64(value);
12911299
case TypeCode.UInt64:
1292-
return value is ulong ? value : Convert.ToUInt64(value);
1300+
if (value is ulong)
1301+
return value;
1302+
var byteValue = value as byte[];
1303+
if (byteValue != null)
1304+
return ConvertToULong(byteValue);
1305+
return Convert.ToUInt64(value);
12931306
case TypeCode.Single:
12941307
return value is float ? value : Convert.ToSingle(value);
12951308
case TypeCode.Double:

tests/ServiceStack.OrmLite.Tests/RowVersionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class RowVersionTests : OrmLiteTestBase
7676
[TestFixtureSetUp]
7777
public void FixtureSetUp()
7878
{
79-
//Dialect = Dialect.Sqlite;
8079
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
8180
using (var dbConn = OpenDbConnection())
8281
{

0 commit comments

Comments
 (0)