0

I am using this code

updateBuilder
    .UPDATE("myTable")
    .SET("UpdatedDate = {0}", updated.UpdatedDate)
    .SET("UpdatedByUserId = {0}", updated.UpdatedByUserId)
    .WHERE("Id = {0}", updated.Id)
    .WHERE("RowVersion = {0}", updated.RowVersion);

And the SQL it generates is like this

exec sp_executesql N'UPDATE myTable
SET UpdatedDate = @p0, UpdatedByUserId = @p1
WHERE Id = @p2 AND RowVersion = @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10

I am guessing that it is adding a value for each element in the byte array, as the property RowVersion = byte[], but how do i fix this?

In entity framework the byte[] is added in SQL like this

@3=0x0000000000560F94

How can i get my byte array to be this?

Gillardo
  • 9,518
  • 18
  • 73
  • 141
  • do you know what this means `{0:X}`.. read up here to answer your question / for an explanation on hexidecimal values http://msdn.microsoft.com/en-us/library/s8s7t687(v=vs.80).aspx – MethodMan Jun 19 '15 at 20:29
  • do a google search how to convert a byte[] to hexadecimal string – MethodMan Jun 19 '15 at 20:38
  • What is the underlying data type for RowVersion? byte or string? – Brian Mains Jun 20 '15 at 02:15
  • In c# row version is byte []. On sql row version is a timestamp column – Gillardo Jun 20 '15 at 05:21
  • try to convert the byte[] to hexadecimal string and then use it instead of directly using byte[]. for the information regarding converting byte[] to hexadecimal string follow the following stackoverflow link. http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa – Ramesh Babu Jun 20 '15 at 06:53
  • tried that, but it then puts ' ' around the value in SQL and i get a conversion error – Gillardo Jun 20 '15 at 07:41

1 Answers1

1

This is a known issue, the answer is here.

Max Toro
  • 28,282
  • 11
  • 76
  • 114