Skip to content

SqlServer does not read DbNull for null value in rowversion column #22256

Closed

Description

As @ErikEJ found #21269 (comment)

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.

dataReader.IsDBNull(0) ? default(Nullable<ulong>) : (Nullable<ulong>)dataReader.GetFieldValue<byte[]>(0) == null ? 0 : BitConverter.ToUInt64(
        value: NumberToBytesConverter<ulong>.ReverseLong(dataReader.GetFieldValue<byte[]>(0)), 
        startIndex: 0);

Method body of ReverseLong which generates the error

        private static byte[] ReverseLong(byte[] bytes)
            => new[] { bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0] };

May be we need to add customized converter for SqlServer in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions