1212using System . Linq ;
1313using System . Text ;
1414using Microsoft . Data . SqlClient ;
15+ using OnTopic . Data . Sql . Models ;
1516using OnTopic . Internal . Diagnostics ;
1617using OnTopic . Metadata ;
1718using OnTopic . Repositories ;
@@ -370,40 +371,21 @@ List<Topic> unresolvedRelationships
370371 return topic . Id ;
371372 }
372373
373- /*------------------------------------------------------------------------------------------------------------------------
374- | Establish attribute containers with schema
375- \-----------------------------------------------------------------------------------------------------------------------*/
376- var extendedAttributes = new StringBuilder ( ) ;
377- var attributes = new DataTable ( ) ;
378-
379- attributes . Columns . Add (
380- new DataColumn ( "AttributeKey" ) {
381- MaxLength = 128
382- }
383- ) ;
384- attributes . Columns . Add (
385- new DataColumn ( "AttributeValue" ) {
386- MaxLength = 255
387- }
388- ) ;
389-
390374 /*------------------------------------------------------------------------------------------------------------------------
391375 | Add indexed attributes that are dirty
392376 \-----------------------------------------------------------------------------------------------------------------------*/
393- foreach ( var attributeValue in indexedAttributeList ) {
377+ var attributeValues = new AttributeValuesDataTable ( ) ;
394378
395- var record = attributes . NewRow ( ) ;
396- record [ "AttributeKey" ] = attributeValue . Key ;
397- record [ "AttributeValue" ] = attributeValue . Value ;
379+ foreach ( var attributeValue in indexedAttributeList ) {
380+ attributeValues . AddRow ( attributeValue . Key , attributeValue . Value ) ;
398381 attributeValue . IsDirty = false ;
399-
400- attributes . Rows . Add ( record ) ;
401-
402382 }
403383
404384 /*------------------------------------------------------------------------------------------------------------------------
405385 | Add extended attributes
406386 \-----------------------------------------------------------------------------------------------------------------------*/
387+ var extendedAttributes = new StringBuilder ( ) ;
388+
407389 extendedAttributes . Append ( "<attributes>" ) ;
408390
409391 foreach ( var attributeValue in extendedAttributeList ) {
@@ -418,7 +400,7 @@ List<Topic> unresolvedRelationships
418400 //extended attribute, as it persists that version history, while removing ambiguity over which record is authoritative.
419401 //This is also useful for supporting arbitrary attribute values, since they may be moved from indexed to extended
420402 //attributes if their length exceeds 255.
421- addUnmatchedAttribute ( attributeValue . Key ) ;
403+ attributeValues . AddRow ( attributeValue . Key ) ;
422404
423405 }
424406
@@ -430,14 +412,7 @@ List<Topic> unresolvedRelationships
430412
431413 //Loop through the content type's supported attributes and add attribute to null attributes if topic does not contain it
432414 foreach ( var attribute in GetUnmatchedAttributes ( topic ) ) {
433- addUnmatchedAttribute ( attribute . Key ) ;
434- }
435-
436- void addUnmatchedAttribute ( string key ) {
437- var record = attributes . NewRow ( ) ;
438- record [ "AttributeKey" ] = key ;
439- record [ "AttributeValue" ] = null ;
440- attributes . Rows . Add ( record ) ;
415+ attributeValues . AddRow ( attribute . Key ) ;
441416 }
442417
443418 /*------------------------------------------------------------------------------------------------------------------------
@@ -472,7 +447,7 @@ void addUnmatchedAttribute(string key) {
472447 }
473448 command . AddParameter ( "Version" , version . Value ) ;
474449 command . AddParameter ( "ExtendedAttributes" , extendedAttributes ) ;
475- command . Parameters . AddWithValue ( "@Attributes" , attributes ) ;
450+ command . Parameters . AddWithValue ( "@Attributes" , attributeValues ) ;
476451 command . AddOutputParameter ( ) ;
477452
478453 /*------------------------------------------------------------------------------------------------------------------------
@@ -513,7 +488,7 @@ void addUnmatchedAttribute(string key) {
513488 \-----------------------------------------------------------------------------------------------------------------------*/
514489 finally {
515490 command ? . Dispose ( ) ;
516- attributes . Dispose ( ) ;
491+ attributeValues . Dispose ( ) ;
517492 }
518493
519494 /*------------------------------------------------------------------------------------------------------------------------
0 commit comments