Skip to content

Support XML data type for MSSQL - #3006

Open
Jerry Nixon (JerryNixon) with Copilot wants to merge 7 commits into
mainfrom
copilot/support-xml-data-type-mssql
Open

Support XML data type for MSSQL#3006
Jerry Nixon (JerryNixon) with Copilot wants to merge 7 commits into
mainfrom
copilot/support-xml-data-type-mssql

Conversation

Copilot AI commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

Why make this change?

SQL Server's XML data type (supported since SQL Server 2005) was not recognized by DAB, preventing use of tables with XML columns.

What is this change?

Treat XML as a string type, consistent with how SQL Server emits it via FOR JSON:

  • SqlTypeConstants.cs: Mark xml as supported (true)
  • TypeHelper.cs: Map SqlDbType.Xmltypeof(string)
  • DatabaseSchema-MsSql.sql: Add xml_types column to type_table with test data for integration testing

DAB passes XML as string in both directions; SQL Server handles validation.

How was this tested?

  • Integration Tests
  • Unit Tests

Existing CLRtoJsonValueTypeUnitTests now validates (xml,True) test case passes. Added xml_types xml column to type_table in the MsSql test database schema with various XML test data to enable integration testing of XML data type operations.

Sample Request(s)

POST /documents
Content-Type: application/json

{
  "id": 1,
  "metadata": "<author>admin</author>"
}

Response:

{
  "value": [
    {
      "id": 1,
      "metadata": "<author>admin</author>"
    }
  ]
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for SQL Server's XML data type by treating it as a string type, consistent with how SQL Server emits XML content via FOR JSON.

  • Marks XML as a supported SQL type in SqlTypeConstants.cs
  • Maps SqlDbType.Xml to typeof(string) in TypeHelper.cs

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Core/Models/SqlTypeConstants.cs Marks xml type as supported (changed from false to true)
src/Core/Services/TypeHelper.cs Adds mapping from SqlDbType.Xml to typeof(string) in the type conversion dictionary

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
@RubenCerna2079

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle

Copy link
Copy Markdown
Contributor

Copilot the PR description says that this will close an already closed issue which seems to have nothing to do with XML type, #2698, did you instead mean #2769 ?

Copilot AI commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

Copilot the PR description says that this will close an already closed issue which seems to have nothing to do with XML type, #2698, did you instead mean https://github.com/Azure/data-api-builder/iss...

Correct — the intended issue is #2769 (Support XML data type for MSSQL). I'll update the PR description.

@JerryNixon

Copy link
Copy Markdown
Contributor

Copilot, reevaluate this implementation.

Copilot AI commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Copilot, reevaluate this implementation.

Implementation reevaluated and validated:

Core changes (353b1ea):

  1. SqlTypeConstants.cs: Marked xml as supported (true)
  2. TypeHelper.cs: Added [SqlDbType.Xml] = typeof(string) — consistent with other text types (NVarChar, Text, VarChar, etc.)

Test schema (3ce04b9):
3. DatabaseSchema-MsSql.sql: Added xml_types xml column to type_table with 5 test values including NULL

Behavior:

  • DAB treats XML columns as string in both directions
  • SQL Server validates XML well-formedness at runtime
  • GraphQL and REST expose XML as String type
  • No special parsing/formatting — consistent with FOR JSON behavior

The implementation is minimal and correct.

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

Labels

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

6 participants