Description
The convert_type_to_sqlserver function in sql_type_converter.py currently does not handle nvarchar and datetime2 as explicit base types. When a data contract field uses these SQL Server-specific types directly, they are not properly mapped and fall through the conversion logic.
Proposed Change
Add explicit handling for nvarchar and datetime2 in convert_type_to_sqlserver:
-
nvarchar: When a field's base type is nvarchar, it should be passed through _attach_params_if_present("nvarchar", field) to preserve any length parameters (e.g., nvarchar(255)).
-
datetime2: When a field's base type is datetime2, it should be passed through _attach_params_if_present("datetime2", field) to preserve any precision parameters.
Code Change
# In datacontract/export/sql_type_converter.py — convert_type_to_sqlserver()
if base_type in ["nvarchar"]:
return _attach_params_if_present("nvarchar", field)
if base_type in ["datetime2"]:
return _attach_params_if_present("datetime2", field)
Motivation
Users working with SQL Server data contracts may define fields with native SQL Server types like nvarchar (for Unicode strings) or datetime2 (for high-precision timestamps). Without this handling, exporting such contracts to SQL doesn't produce the correct DDL.
Note
I wanted to send you the PR for your review, but I don´t have permissions to push branches.
Description
The
convert_type_to_sqlserverfunction in sql_type_converter.py currently does not handlenvarcharanddatetime2as explicit base types. When a data contract field uses these SQL Server-specific types directly, they are not properly mapped and fall through the conversion logic.Proposed Change
Add explicit handling for
nvarcharanddatetime2inconvert_type_to_sqlserver:nvarchar: When a field's base type isnvarchar, it should be passed through_attach_params_if_present("nvarchar", field)to preserve any length parameters (e.g.,nvarchar(255)).datetime2: When a field's base type isdatetime2, it should be passed through_attach_params_if_present("datetime2", field)to preserve any precision parameters.Code Change
Motivation
Users working with SQL Server data contracts may define fields with native SQL Server types like nvarchar (for Unicode strings) or datetime2 (for high-precision timestamps). Without this handling, exporting such contracts to SQL doesn't produce the correct DDL.
Note
I wanted to send you the PR for your review, but I don´t have permissions to push branches.