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

Commit 3c0ff14

Browse files
committed
Convert RowVersion byte[] into ulong for SqlServer
1 parent 24a5a14 commit 3c0ff14

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/ServiceStack.OrmLite.SqlServer/SqlServerOrmLiteDialectProvider.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ public override string GetQuotedTableName(ModelDefinition modelDef)
100100
return string.Format("\"{0}\".\"{1}\"", escapedSchema, NamingStrategy.GetTableName(modelDef.ModelName));
101101
}
102102

103+
public override void SetDbValue(FieldDefinition fieldDef, IDataReader reader, int colIndex, object instance)
104+
{
105+
if (fieldDef.IsRowVersion)
106+
{
107+
var bytes = reader.GetValue(colIndex) as byte[];
108+
if (bytes != null)
109+
{
110+
Array.Reverse(bytes); //Correct Endianness
111+
var ulongValue = BitConverter.ToUInt64(bytes, 0);
112+
try
113+
{
114+
fieldDef.SetValueFn(instance, ulongValue);
115+
}
116+
catch (NullReferenceException ignore) { }
117+
}
118+
}
119+
else
120+
{
121+
base.SetDbValue(fieldDef, reader, colIndex, instance);
122+
}
123+
}
124+
103125
public override object ConvertDbValue(object value, Type type)
104126
{
105127
try
@@ -324,6 +346,9 @@ public override string ToChangeColumnNameStatement(Type modelType, FieldDefiniti
324346
public override string GetColumnDefinition(string fieldName, Type fieldType, bool isPrimaryKey, bool autoIncrement,
325347
bool isNullable, bool isRowVersion, int? fieldLength, int? scale, string defaultValue, string customFieldDefinition)
326348
{
349+
if (isRowVersion)
350+
return "{0} rowversion NOT NULL".Fmt(fieldName);
351+
327352
var definition = base.GetColumnDefinition(fieldName, fieldType, isPrimaryKey, autoIncrement,
328353
isNullable, isRowVersion, fieldLength, scale, defaultValue, customFieldDefinition);
329354

0 commit comments

Comments
 (0)