Skip to content

Fixed length binary columns in user defined table types fail when constructed #413

@daniellittledev

Description

@daniellittledev

Issue Summary

When using a user defined table type with a fixed length binary column the wrong constructor for SqlMetaData is used resulting in the following exception.

System.ArgumentException: 'The dbType Binary is invalid for this constructor.'

This line looks like it's causing the issue, which incorrectly assumes if it is a fixed length that it can safely use the two parameter constructor:

if typeInfo.IsFixedLength then

To Reproduce

  1. Create a custom table type
CREATE TYPE [dbo].[CustomTableType] AS TABLE(
	[Value] [binary](16)
)
  1. Use the type in a query
type StaticProvider =
    SqlCommandProvider<"
        Declare @Updates as CustomTableType = @Inputs;
    " , staticConnectionString>

use cmd = new StaticProvider(context.connection, transaction = context.transaction)
cmd.AsyncExecute(
    data.inputs
    |> List.map(fun x ->
        StaticProvider.CustomTableType( // <--- Error in constructor
            Value = x.value
        )
    )

Error

System.ArgumentException: 'The dbType Binary is invalid for this constructor.'

Expected behavior

There should not be an error in this case.

What you can do

  • I am willing to contribute a PR with a unit test showcasing the issue
  • I am willing to test the bug fix before next release

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions