Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize DataTypeName from DataTable.TableName in TableValuedParameter #2139

Open
0UserName opened this issue Jan 1, 2025 · 0 comments
Open

Comments

@0UserName
Copy link

0UserName commented Jan 1, 2025

Proposal

Is it possible to make changes like these in the method TableValuedParameter.AddParameter:

void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{
    var param = command.CreateParameter();
    param.ParameterName = name;
    Set(param, table, typeName);

    param.GetType().GetProperty("DataTypeName")?.SetValue(param, table.TableName);

    command.Parameters.Add(param);
}

Theoretically, the property name could be UdtTypeName, in which case a configuration mechanism should be provided.


Motivation

My goal is to write a custom DataTable converter for Npgsql, enabling its use in a manner similar to how it functions with SQL Server. DataTable can be represented as an array of composite types, making it quite feasible to transfer the table to the server (at least for primitive types like int, long. string, etc)

However, the driver is designed such that if multiple composite types are mapped to the same converter, the first one will be selected. This will result in the data sent not matching the signature of the stored procedure (OIDs).

One option is to initialize the property before passing the parameter to the driver, so that the filtering is accurate, but transparent to the client. This would help eliminate the need to explicitly create parameters and make the transition between databases smoother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant