You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SqlServer does not read DbNull for null value in rowversion column #22256
OK, rowversion is never null, and always gets a value assigned by the database engine: A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column.
In our shaper when reading value of the column solely,
we generate checks but all checks are bypassed and we throw IndexOutOfRangeException.
As I discovered by me in my original issue, rowversion cannot be NULL in Sql Server, NULL is represented by 0x. This means that the IsDBNull check which is used by EntityFrameworkCore is not enough for rowversion columns.
The bug is the following. In the BufferedDataReader.BufferedDataRecord.ReadRow method the following check is performed if (!(_tempNulls[_currentRowNumber * _nullCount + nullIndex] = _underlyingReader.IsDBNull(i))). For a reason unknown to me IsDBNull always returns false when the data type is timestamp (rowversion), see my StackOverflow post about it at https://stackoverflow.com/questions/62410830/timestamp-isdbnull.
What this means is that, in the case of timestamp its value will always be Array.Empty, see screenshot below.
Unless there's something obvious I'm missing here which would render this all wrong, in which case I apologize in advance, these are the paths I currently see:
Extend the IsDBNull check with a type check on rowversion, could be based on EntityFrameworkCore metadata or DbDataReader.GetDataTypeName (the last one seems rather dirty);
Add a value converter specifically for rowversion which can deal with empty arrays instead of the default NumberToBytesConverter;
Adjust the NumberToBytesConverter to be able to handle empty arrays, as is done currently.
Do let me know which one of the above paths you wish to take, or if you wish to take a different path, so that I can adjust my pull request.
I'm glad you are finally looking into the direction of a customized converter for Sql Server, as I suggested. Unless you can contact the Sql Server team about this, but due to backwards compatibility they might be afraid to correct it.
Activity
smitpatel commentedon Aug 26, 2020
Added a disabled regression test in codebase
Fix issue#12518
Fix issue#12518
Fix issue#12518 (#22257)
bdebaere commentedon Aug 27, 2020
As I discovered by me in my original issue, rowversion cannot be NULL in Sql Server, NULL is represented by 0x. This means that the IsDBNull check which is used by EntityFrameworkCore is not enough for rowversion columns.
I'm glad you are finally looking into the direction of a customized converter for Sql Server, as I suggested. Unless you can contact the Sql Server team about this, but due to backwards compatibility they might be afraid to correct it.
smitpatel commentedon Aug 27, 2020
@bdebaere - Neither of the aforementioned options are right solution.
bdebaere commentedon Aug 31, 2020
@smitpatel
is equal to
Enable test for Projecting_column_with_value_converter_of_ulong_byte_…
Enable test for Projecting_column_with_value_converter_of_ulong_byte_…