@@ -46,9 +46,9 @@ internal TableBuilder(string schemaName, string tableName)
4646 /// IsNullable=True default, but for test setup NOT NULL is more
4747 /// useful so explicit assertions on NULL-handling become opt-in.
4848 /// </summary>
49- public TableBuilder Column ( string name , string sqlType , bool nullable = false , bool identity = false , int identitySeed = 1 , int identityIncrement = 1 , PeriodColumnKind periodKind = PeriodColumnKind . None , string ? collation = null , bool rowGuidCol = false )
49+ public TableBuilder Column ( string name , string sqlType , bool nullable = false , bool identity = false , int identitySeed = 1 , int identityIncrement = 1 , PeriodColumnKind periodKind = PeriodColumnKind . None , string ? collation = null , bool rowGuidCol = false , string ? xmlSchemaCollection = null )
5050 {
51- _columns . Add ( new ColumnDef ( name , sqlType , nullable , identity , identitySeed , identityIncrement , periodKind , collation , rowGuidCol ) ) ;
51+ _columns . Add ( new ColumnDef ( name , sqlType , nullable , identity , identitySeed , identityIncrement , periodKind , collation , rowGuidCol , xmlSchemaCollection ) ) ;
5252 _order . Add ( ( Computed : false , _columns . Count - 1 ) ) ;
5353 return this ;
5454 }
@@ -462,12 +462,36 @@ private XElement ColumnElement(XNamespace ns, ColumnDef column)
462462 if ( column . RowGuidCol )
463463 element . Add ( PropertyElement ( ns , "IsRowGuidColumn" , "True" ) ) ;
464464
465+ var typeSpecifier = column . XmlSchemaCollectionRef is { } collectionRef
466+ ? XmlTypeSpecifierElement ( ns , collectionRef )
467+ : TypeSpecifierElement ( ns , column . SqlType ) ;
465468 element . Add ( new XElement ( ns + "Relationship" ,
466469 new XAttribute ( "Name" , "TypeSpecifier" ) ,
467- new XElement ( ns + "Entry" , TypeSpecifierElement ( ns , column . SqlType ) ) ) ) ;
470+ new XElement ( ns + "Entry" , typeSpecifier ) ) ) ;
468471 return element ;
469472 }
470473
474+ /// <summary>
475+ /// Emits a <c>SqlXmlTypeSpecifier</c> bound to a schema collection — the
476+ /// shape DACFx uses for a typed-xml column (<c>xml([schema].[collection])</c>).
477+ /// A <c>Type</c> relationship to the <c>[xml]</c> built-in plus an
478+ /// <c>XmlSchemaCollection</c> relationship to the collection reference.
479+ /// </summary>
480+ private static XElement XmlTypeSpecifierElement ( XNamespace ns , string collectionRef ) =>
481+ new ( ns + "Element" ,
482+ new XAttribute ( "Type" , "SqlXmlTypeSpecifier" ) ,
483+ new XElement ( ns + "Relationship" ,
484+ new XAttribute ( "Name" , "Type" ) ,
485+ new XElement ( ns + "Entry" ,
486+ new XElement ( ns + "References" ,
487+ new XAttribute ( "Name" , "[xml]" ) ,
488+ new XAttribute ( "ExternalSource" , "BuiltIns" ) ) ) ) ,
489+ new XElement ( ns + "Relationship" ,
490+ new XAttribute ( "Name" , "XmlSchemaCollection" ) ,
491+ new XElement ( ns + "Entry" ,
492+ new XElement ( ns + "References" ,
493+ new XAttribute ( "Name" , collectionRef ) ) ) ) ) ;
494+
471495 private static XElement TypeSpecifierElement ( XNamespace ns , string sqlType )
472496 {
473497 // Bracketed 2-part name → UDDT reference (no ExternalSource, no
@@ -550,7 +574,7 @@ public enum PeriodColumnKind
550574}
551575
552576/// <summary>Column metadata captured by <see cref="TableBuilder.Column"/>.</summary>
553- internal readonly record struct ColumnDef ( string Name , string SqlType , bool Nullable , bool Identity = false , int IdentitySeed = 1 , int IdentityIncrement = 1 , PeriodColumnKind PeriodKind = PeriodColumnKind . None , string ? Collation = null , bool RowGuidCol = false ) ;
577+ internal readonly record struct ColumnDef ( string Name , string SqlType , bool Nullable , bool Identity = false , int IdentitySeed = 1 , int IdentityIncrement = 1 , PeriodColumnKind PeriodKind = PeriodColumnKind . None , string ? Collation = null , bool RowGuidCol = false , string ? XmlSchemaCollectionRef = null ) ;
554578
555579/// <summary>Base for constraint declarations accumulated on a table.</summary>
556580internal abstract record ConstraintDef ( string Name ) ;
0 commit comments